木偶:如何避免等待x ms以确保页面已加载

时间:2020-04-26 12:50:57

标签: puppeteer

登录到网站后,我需要Puppeteer单击位于“”标记中的“#shadow-root”中的“ vaadin-tab”。我这样登录:

 await page.click("#login-container > vaadin-vertical-layout > vaadin-button");

然后必须

await page.waitFor(5000); // 5000 is a rule-of-thumb value (2000 does not work)

开始之前

await page.evaluate(
        () => {
    var appNav = document.querySelector("body > div.gradient > div:nth-child(1) > app-navigation");

    const element = appNav.shadowRoot.querySelector("#special-tab");

    element.click();

});

我想避免使用waitFor(5000),因为我不确定它在所有情况下是否都足够,为了安全起见,我可能需要waitFor(10000),我的访客可能会觉得它很慢也许有些忙碌的一天甚至还不够。

所以我更喜欢

await page.waitForNavigation({waitUntil: 'networkidle0'}); // does not wait. Also tested with networkidle2

    await page.waitForSelector("body > div.gradient > div:nth-child(1) > app-navigation", {visible : true}); // does not work either with visible or without it

我该如何使用Puppeteer?

任何帮助表示赞赏:)

0 个答案:

没有答案