Key takeaways
- Puppeteer’s
page.clickdoes not wait for the selector: it throws if the element is not there yet. - Wait first with
waitForSelector, or usepage.locator(...).click(), which waits for the element to be visible, enabled and stable. - If a click does nothing, check for an overlay intercepting it before blaming the selector.
LoadFocus is an easy to use cloud testing tool: you don’t need any setup, it runs from the browser. It helps you understand your website’s and web services’ performance and find potential bottlenecks before your customers do. Run a free website speed test today.
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:
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:
- 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 no element matches the selector, it throws an error straight away; it does not wait for the element to appear. On pages that render late, wait first, or use a locator, which waits for the element to be visible, enabled and stable before it clicks (pptr.dev page interactions guide, November 2026):
await page.waitForSelector('.clickButton', { visible: true });
await page.click('.clickButton');
// or, with a locator
await page.locator('.clickButton').click();
More details can be found in the Puppeteer documentation: pptr.dev/api/puppeteer.page.click
Check out more details of how to take screenshots with Puppeteer using Headless Chrome Browser.
Frequently Asked Questions
Does page.click wait for the element?
No. page.click scrolls the element into view and clicks it, but if the selector matches nothing yet it throws. Call waitForSelector first, or use page.locator(selector).click(), which waits for the element to be visible, enabled and stable.
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.