[英]How to click on a button within an iframe using Puppeteer
我正在嘗試自動登錄 Nike BR 網站(與其他網站不同)。 輸入 email 和密碼后,我需要單擊 iframe 按鈕“進入/登錄”,但我不知道該怎么做。
這是代碼:
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);
})();
嘗試:
const buttonInput = await frame.waitForXPath('//input[@type="button"]');
await buttonInput.click();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.