Search code examples
javascriptnode.jsgoogle-chromechromiumpuppeteer

How can I click display:none element with puppeteer?


I want to click an element which display property is none. How can I do this?

Code:

page.click(".foo");

Solution

  • You can use the JavaScript click function. This function will trigger the elements click event and does not care about whether the element is visible or not.

    You need to use page.evaluate to execute it inside the page.

    Example:

    await page.evaluate(() => {
      document.querySelector('.foo').click();
    });