Clicking a button within an iframe with puppeteer

Viewed 1132

Trying to click on the "I accept all cookies" button which is inside iFrame (The popup only show for EU country ip). You can check here also jsfiddle.net/#&togetherjs=VgKpE0jfJF.

enter image description here

//index.js
const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    headless:false,
      ignoreHTTPSErrors: true,
      slowMo: 50,
      args: ['--window-size=1440,900', '--disable-gpu', "--disable-features=IsolateOrigins,site-per-process", '--blink-settings=imagesEnabled=true']
    });
  const page = await browser.newPage();
  await page.goto('https://www.oracle.com/cloud/cost-estimator.html');

  await page.waitFor(3000)
  const frame = page.frames().find(f => f.name() === 'iframe');
  const acceptBtn = await frame.$(`a[class="call"]`);
  await acceptBtn.click();

  await page.screenshot({path: 'example.png'});

  //await browser.close();
})();

The error i get

UnhandledPromiseRejectionWarning: TypeError: Cannot read property '$' of undefined
    at

Please help. Thanks

1 Answers

As far as I can tell, this iframe has no name in the HTML code, so you can try its src (URL):

const frame = page.frames().find(f => f.url().startsWith('https://consent-pref.trustarc.com/'));
Related