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.