Key takeaways

  • Puppeteer's click waits for the selector, but not for the element to be genuinely interactive.
  • Wait for visibility explicitly when the page animates or loads content late.
  • If a click does nothing, check for an overlay intercepting it before blaming the selector.

LoadFocus – is a easy to use cloud testing tool, and you don’t need any setup, it runs from the browser. It helps you understand better your Website’s and WebServices’ performance and find potential bottleneck before your customers do. Run a free website speed test today.

Is Your Infrastructure Ready for Global Traffic Spikes?

Unexpected load surges can disrupt your services. With LoadFocus’s cutting-edge Load Testing solutions, simulate real-world traffic from multiple global locations in a single test. Our advanced engine dynamically upscales and downscales virtual users in real time, delivering comprehensive reports that empower you to identify and resolve performance bottlenecks before they affect your users.

View Pricing
Real-time insights
Discover More
Global scalability

Using Puppeteer to interact with the UI elements from web pages is quite simple. All you need to do is to open a new page with Puppeteer:


const page = await browser.newPage();

Then, all you have to do, is identifying the element you want to perform the action, click in our case:
[emaillocker]


await page.click('.clickButton');

Puppeteer comes with a set of options for the click action, all optional:
According to the documentation, you can have these options sent to the click action:

Think your website can handle a traffic spike?

Fair enough, but why leave it to chance? Uncover your website’s true limits with LoadFocus’s cloud-based Load Testing for Web Apps, Websites, and APIs. Avoid the risk of costly downtimes and missed opportunities—find out before your users do!

Effortless setup No coding required
  • button left, right, or middle, defaults to left.
  • clickCount defaults to 1. See UIEvent.detail.
  • delay Time to wait between mouse down and mouse up in milliseconds. Defaults to 0.

Click method will scroll into view the selected element (if it’s found, and if the element is not in the viewport) and click in the center of the element.
If the element is not found, it will throw an error.

More details can be found on the documentation page from Puppeteer: https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md

Check out more details of how to take screenshots with Puppeteer using Headless Chrome Browser.

 

LoadFocus is an all-in-one Cloud Testing Platform for Websites and APIs for Load Testing, Apache JMeter Load Testing, Page Speed Monitoring and API Monitoring!

Effortless setup No coding required

LoadFocus – is a easy to use cloud testing tool, and you don’t need any setup, it runs from the browser. It helps you understand better your Website’s and WebServices’ performance and find potential bottleneck before your customers do. Run a free website speed test today.
[/emaillocker]

Frequently Asked Questions

Does page.click wait for the element?

It waits for the selector to appear and it scrolls the element into view, but it does not wait for the element to become genuinely interactive. On animated or late loading pages, wait for visibility explicitly first.

What happens if the selector is not found?

Puppeteer throws. That is usually the outcome you want in a test, but it means a click on an optional element needs a guard rather than a bare call.

The click runs without error but nothing happens. Why?

Something is almost certainly intercepting it: a cookie banner, a modal backdrop or an invisible overlay sitting above your element. Puppeteer clicks the centre point of the element, so whatever occupies that point receives the event.

Related reading

Chris
Head of Content at LoadFocus

Chris leads content and oversees development across the services this blog covers. The guides and tool comparisons here come out of the same decisions that shape what ships.

How fast is your website? Free Website Speed Test