How to click on a button within an iframe using Puppeteer

Viewed 160

I'm trying to automate login to the Nike BR website (that is different from the others). After typing the email and password, I need to to click on the iframe button "ENTRAR/LOGIN" but I dont see how to do this.

This is the code:

const puppeteer = require('puppeteer');
(async () => {
  const browser = await puppeteer.launch({ headless: false });
  const page = await browser.newPage();

  await page.setViewport({ width: 1920, height: 1080 });
  await page.goto('https://www.nike.com.br');
  const login = await page.waitForXPath('//*[@id="anchor-acessar-unite-oauth2"]');
  await login.click();

  const frameElement = await page.waitForXPath('//iframe[@id="nike-unite-oauth2-iframe"]');
  const frame = await frameElement.contentFrame();

  const emailInput = await frame.waitForXPath('//input[@name="emailAddress"]');

  const passwordInput = await frame.waitForXPath('//input[@name="password"]');
  await emailInput.evaluate((elem) => elem.value = 'test@hotmail.com');
  await passwordInput.evaluate((elem) => elem.value = 'test123')
  await page.waitFor(1000);
})();
1 Answers

Try:

const buttonInput = await frame.waitForXPath('//input[@type="button"]');
await buttonInput.click();
Related