Skip to main content

How to Click on Element with Puppeteer and Chrome

How to Click on Element with Puppeteer and Chrome

Key takeaways

  • Puppeteer’s page.click does not wait for the selector: it throws if the element is not there yet.
  • Wait first with waitForSelector, or use page.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.

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.

Weekly tips right in your inbox.

Don’t miss out on the latest testing tips and tricks, tools and news related to software testing.

Already +20,000 members in the list.

The Load Testing Platform with AI That Explains Your Results

Load test websites and APIs from 25 cloud regions, monitor page speed and uptime, and get AI analysis that explains your results in plain English.

Cloud load testing, website speed and API monitoring in one place.

Hi there! Can I share a cool thing I'm working on with you?

A software testing newsletter that sparks joy.

Our goal is to create helpful content for software developers and testers.

If you're not into it, you can unsubscribe instantly.