Javascript 在木偶演员的headless true模式中找不到选择器的节点

Javascript 在木偶演员的headless true模式中找不到选择器的节点,javascript,node.js,puppeteer,google-chrome-headless,headless-browser,Javascript,Node.js,Puppeteer,Google Chrome Headless,Headless Browser,我的环境: 木偶演员版本:1.20.0 平台/操作系统版本:Ubuntu 18.04.3 LTS Node.js版本:8.10.0 铬/78.0.3882.0 此错误内容已在终端中打印: (node:18157) UnhandledPromiseRejectionWarning: Error: No node found for selector: #identifierNext at assert (/home/hoangdd3/node_modules/puppeteer/lib

我的环境:

  • 木偶演员版本:1.20.0
  • 平台/操作系统版本:Ubuntu 18.04.3 LTS
  • Node.js版本:8.10.0
  • 铬/78.0.3882.0
此错误内容已在终端中打印:

(node:18157) UnhandledPromiseRejectionWarning: Error: No node found for selector: #identifierNext
    at assert (/home/hoangdd3/node_modules/puppeteer/lib/helper.js:279:11)
    at DOMWorld.click (/home/hoangdd3/node_modules/puppeteer/lib/DOMWorld.js:366:5)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
  -- ASYNC --
    at Frame.<anonymous> (/home/hoangdd3/node_modules/puppeteer/lib/helper.js:111:15)
    at Page.click (/home/hoangdd3/node_modules/puppeteer/lib/Page.js:1037:29)
    at puppeteer.launch.then (/home/hoangdd3/pupperteer/example.js:15:16)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
(node:18157) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:18157) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

看起来像是在
等待页面中。单击('identifierNext')没有id=identifierNext的元素

代替
等待页面。单击('identifierNext')

尝试使用

const next = await page.waitForSelector('#identifierNext');
await next.click();
不同的文本
单击('identifierNext')
waitForSelector并单击

waitForSelector-可以等待一个元素30000s,以便将一个元素添加到DOM中


单击-如果DOM中现在没有元素,单击将拒绝承诺

您面临的问题涉及选择器,它们根本不存在:)。
headless:true
中提供的html与
headless:false

headless:false

有一些代码将在
headless:true

const puppeteer = require('puppeteer');

(async () => {
    const browser = await puppeteer.launch({
        headless: true,
    });
    const page = await browser.newPage();

    await page.goto('https://accounts.google.com/signin/v2/identifier?flowName=GlifWebSignIn&flowEntry=ServiceLogin',  {"waitUntil" : "networkidle0"});
    await page.waitFor(2000);

    await page.click('#Email');
    await page.keyboard.sendCharacter('phamvancuong4584sg@gmail.com');

    await page.click('#next');

    await page.waitFor(2000);

    await page.click('#Passwd');

    await page.keyboard.sendCharacter('test');
    await page.click('#signIn');

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

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

在屏幕上
example.png
你可以看到密码不正确的信息(测试)。

我和你有同样的问题。如果你已经解决了,请告诉我。我相信一定有某种混淆,以防止单击此按钮。@user2481095:请参阅下面的domlas答案。我也这样做了,并取得了成功。对于
headless:true
如何确定选择器(即
页面。单击(“#下一步”)
?@RizaKhan在给定时间,我使用docker以某种黑客方式完成了这项工作,并通过活动web套接字连接到chrome实例。有一种ofc更快的方法可以为headless google页面获取DOM。请看:
const puppeteer = require('puppeteer');

(async () => {
    const browser = await puppeteer.launch({
        headless: true,
    });
    const page = await browser.newPage();

    await page.goto('https://accounts.google.com/signin/v2/identifier?flowName=GlifWebSignIn&flowEntry=ServiceLogin',  {"waitUntil" : "networkidle0"});
    await page.waitFor(2000);

    await page.click('#Email');
    await page.keyboard.sendCharacter('phamvancuong4584sg@gmail.com');

    await page.click('#next');

    await page.waitFor(2000);

    await page.click('#Passwd');

    await page.keyboard.sendCharacter('test');
    await page.click('#signIn');

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

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