【问题标题】:How would puppeteer wait for all redirectspuppeteer 如何等待所有重定向
【发布时间】:2018-07-30 19:48:52
【问题描述】:

我有一个 puppeteer 项目,需要提交一个表单,然后等待下一页。问题是要进入下一页,网站会进行大约 3-4 次重定向,然后才会开始加载实际内容。

Puppeteer 似乎卡在了中间的某个地方。

我该如何解决这个问题?

这是我的代码:

await page.goto('<url>/Login.html', {'waitUntil': 'networkidle0', timeout: 60000});

await page.click(USERID_SLCT);
await page.keyboard.type(creds.userId);
await page.click(PWD_SLCT);
await page.keyboard.type(creds.pwd);
await page.click(LOGINBTN_SLCT);

await page.waitForNavigation({'waitUntil': 'networkidle0'});

await timeout(240000); // wait for the redirects to be finished

await page.waitForSelector(BTN_SLCT, {timeout: 240000}); // make sure the page is loaded <-- would fail here

await page.screenshot({path: './screenshots/mainpage.png'});

【问题讨论】:

  • 您是如何决定240000 超时的?
  • 尝试了 30 秒、60 秒、120 秒、240 秒……没有任何帮助。通过常规浏览器访问此页面时 - 大约需要 3-5 秒。

标签: javascript node.js puppeteer google-chrome-headless


【解决方案1】:

我遇到了类似的问题,并通过在所需页面中等待特定选择器来解决它。

        await page.waitForSelector('#manage-trips', { visible: true, timeout: 0 });

【讨论】:

    猜你喜欢
    • 2019-04-05
    • 2022-07-27
    • 1970-01-01
    • 1970-01-01
    • 2018-02-20
    • 2021-11-07
    • 2021-02-05
    • 2021-10-29
    • 2020-08-10
    相关资源
    最近更新 更多