[英]How to tell if user just navigated to the page or was waiting on the page?
[英]Puppeteer how to check if page is navigated and perform task if not navigated
在登录页面上,我试图弄清楚 google recaptcha 是否出现。 如果是这样,我想运行一个代码块,否则像往常一样导航。
await page.goto(
url
);
await page.waitForSelector("#username");
await page.type("#username", process.env.EMAIL);
await page.type("#password", process.env.PSWD);
await page.$eval("#signIn > div > button", (el) => el.click()) //this line sometimes triggers recaptcha
{//here wait for navigation and check if google captcha appears}
//then run the following code:
await page.solveRecaptchas();
await Promise.all([
page.waitForNavigation(),
page.click("#signIn"),
]);
我试过使用 page.waitForNavigation 但如果出现 recaptcha,它会导致超时。 仅当出现 google recaptcha 时,我该怎么做才能运行底部的代码块?
如果recaptcha-token
存在,我还尝试有条件地运行代码块,但我检查了 dom 和 recaptcha 元素始终存在,并且只提示随机选择图像。 基本上,我有时可以导航而无需执行任何验证码,有时会提示我选择图像。
谢谢!
也许是这样的?
const [_, navigation] = await Promise.allSettled([
element.click(),
page.waitForNavigation(),
]);
if (navigation.status === 'fulfilled') /* There was navigation. */;
else /* There was timeout, no navigation. */;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.