question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do you click using page function?

See original GitHub issue

I want to click this button

<button class="_qv64e">Sign up</button>

but the class is not unique. In the browser console I can select using this

document.querySelectorAll('._qv64e')[1])

can someone tell me how I can do something like this: await page.click(document.querySelectorAll('._qv64e')[1]);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

26reactions
yanivefraimcommented, May 10, 2018

@vsemozhetbyt - I believe you meant: (using querySelectorAll, and not querySelector)

await page.evaluate(() => { document.querySelectorAll('._qv64e')[1].click(); });

One more option (pretty much the same):

await page.$$eval('._qv64e', elements => elements[1].click());
9reactions
vsemozhetbytcommented, May 10, 2018

Try:

await page.evaluate(() => { document.querySelector('._qv64e')[1].click(); });
Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML Button onclick – JavaScript Click Event Tutorial
The onclick event executes a certain functionality when a button is clicked. This could be when a user submits a form, when you...
Read more >
How can I run a JavaScript function with any click on the page?
Right now I'm using <body onload="function"> , which changes some text on the page based on which element is focused on.
Read more >
onclick Event - W3Schools
The onclick event occurs when the user clicks on an HTML element. Mouse Events. Event, Occurs When. onclick, The user clicks on an...
Read more >
HTMLElement.click() - Web APIs | MDN
The HTMLElement.click() method simulates a mouse click on an element. When click() is used with supported elements (such as an <input> ) ...
Read more >
How to run a function with a button click in JavaScript
The first line of code here is using getElementById to go out and select the button and store it in the variable btn....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found