[英]Puppeteer How to check if the page has redirected
我正在嘗試使用waitForNavigation()
檢查頁面是否切換。 這是我正在使用的代碼
if(await page.waitForNavigation() == null ){
console.log('False')
await browser.close()
}else {
console.log('True')
await browser.close()
}
例如,讓我們說屏幕上有一個框,然后您會被重定向到另一個頁面。 我希望 True 或 False 在 console.log 上彈出。
我不得不稍微改變一下答案,但在這里
if(newUrl == startingURL){
console.log('False');
await browser.close()
}else{
console.log('True')
await browser.close()
}
If you only care about redirects, like HTTP redirects & window.location.href
redirects, you can check the URL that you end up on and compare it to the URL you started with:
const startURL = 'https://example.com/redirect-start'
await page.goto(startURL)
if (page.url() === startURL) { console.log('False') }
else { console.log('True') }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.