I am trying to check with waitForNavigation()
to see if the page switches or not.
Here is the code I am using
if ((await page.waitForNavigation()) == null) {
console.log("False");
await browser.close();
} else {
console.log("True");
await browser.close();
}
For example, let us just say a box on the screen is there and you get redirected to another page. I want True
or False
to pop up on the console.log
.
I had to switch up the answer a bit but here it is
if (newUrl == startingURL) {
console.log("False");
await browser.close();
} else {
console.log("True");
await browser.close();
}
I am trying to check with waitForNavigation()
to see if the page switches or not.
Here is the code I am using
if ((await page.waitForNavigation()) == null) {
console.log("False");
await browser.close();
} else {
console.log("True");
await browser.close();
}
For example, let us just say a box on the screen is there and you get redirected to another page. I want True
or False
to pop up on the console.log
.
I had to switch up the answer a bit but here it is
if (newUrl == startingURL) {
console.log("False");
await browser.close();
} else {
console.log("True");
await browser.close();
}
Share
Improve this question
edited Apr 29, 2023 at 10:01
Manas Khandelwal
3,9462 gold badges14 silver badges25 bronze badges
asked Apr 21, 2020 at 18:48
Neik0Neik0
1033 silver badges9 bronze badges
1 Answer
Reset to default 11If you only care about redirects, like HTTP redirects & window.location.href
redirects, you can check the URL that you end up on and pare it to the URL you started with:
const startURL = 'https://example./redirect-start'
await page.goto(startURL)
if (page.url() === startURL) { console.log('False') }
else { console.log('True') }