Categories
JavaScript Answers

How to click on element with text in Puppeteer and JavaScript?

Spread the love

To click on element with text in Puppeteer and JavaScript, we call the click method.

For instance, we write

const [button] = await page.$x("//button[contains(., 'Button text')]");
await button?.click();

to get the buttons with the ‘Button text’ text with the page.$x method.

We destructure the array to get the first one.

Then we call click on the first button to click on the button.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *