Home > Enterprise >  how do I use puppeteer to click 'I agree' button for google cookies
how do I use puppeteer to click 'I agree' button for google cookies

Time:04-29

I am trying to use puppeteer to open google translate and enter text into the detect language field, and then return the result in English. However, I am falling at the first hurdle as the button below won't let me through. I know I can use page.click() but I cannot find a button ID and do not know how to click it otherwise.

screenshot of the button I need to click, and the results of inspecting it

CodePudding user response:

One way would be to select the button using an XPath expression with contains() and then click it:

const [button] = await page.$x("//button[contains(., 'I agree')]");
if (!button) throw new Error("button not found");
await button.click();
  • Related