简体   繁体   English

Puppeteer:未找到选择器的节点 - iframe 中的登录模式

[英]Puppeteer: No node found for selector - Login Modal in iframe

I want to go to the login page, click on the username, and type in the username.我要go到登录页面,点击用户名,输入用户名。

This is what I have so far:这是我到目前为止所拥有的:

const puppeteer = require('puppeteer');

(async () => {
    const browser = await puppeteer.launch({ headless: false, slowMo: 200 });
    const page = await browser.newPage();
    await page.goto('https://fantasy.espn.com/basketball/team');
    await page.waitFor(2000);
    await page.click('#did-ui-view > div > section > section > form > section > div:nth-child(1) > div > label > span.input-wrapper > input');
    await page.waitFor(2000);
    await page.type('#did-ui-view > div > section > section > form > section > div:nth-child(1) > div > label > span.input-wrapper > input', 'hello', { delay: 100 });  
    await browser.close()
})();

I continue to get this error:我继续收到此错误:

 Error: No node found for selector: #did-ui-view > div > section > section > form > section > div:nth-child(1) > div > label > span.input-wrapper > input

I don't get it;我不明白; when I do, document.querySelector in the console with that path, I'm returned the input;当我这样做时,控制台中的document.querySelector会返回输入; why is it not able to find that node?为什么找不到那个节点?

the element is in an iframe. so first you need to get the frame and then select the element from that frame.该元素在 iframe 中。所以首先您需要获取框架,然后 select 来自该框架的元素。 You would typically do:你通常会这样做:

let iframeHandle = await page.$('#disneyid-iframe');
let frame = await iframeHandle.contentFrame();
let inputElement = await frame.waitForSelector('#did-ui-view > div > section > section > form > section > div:nth-child(1) > div > label > span.input-wrapper > input')
await inputElement.type('hello', { delay: 100 });

However, there is an issue with out-of-process frames, so you need to launch chromium with --disable-features=site-per-process .但是,进程外框架存在问题,因此您需要使用--disable-features=site-per-process启动 chromium。 The following should work:以下应该工作:

const browser = await puppeteer.launch({headless: false, args: ['--disable-features=site-per-process']});
const page = await browser.newPage();
await page.goto('https://fantasy.espn.com/basketball/team', {waitUntil: ['load', 'domcontentloaded','networkidle0']});
await page.waitFor(5000);
let iframeHandle = await page.$('#disneyid-iframe');
let frame = await iframeHandle.contentFrame();
let inputElement = await frame.waitForSelector('#did-ui-view > div > section > section > form > section > div:nth-child(1) > div > label > span.input-wrapper > input')
await inputElement.type('hello', { delay: 100 });

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

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