[英]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.