简体   繁体   English

如何使用 Puppeteer 单击 iframe 中的按钮

[英]How to click on a button within an iframe using Puppeteer

I'm trying to automate login to the Nike BR website (that is different from the others).我正在尝试自动登录 Nike BR 网站(与其他网站不同)。 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.输入 email 和密码后,我需要单击 iframe 按钮“进入/登录”,但我不知道该怎么做。

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);
})();

Try:尝试:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM