Rayrun
← Back to Discord Forum

Page has been redirected, or page.url() cannot retrieve the redirected URL

cdpconnect, 1.38.0

This thread is trying to answer question "How can I resolve the issue of page redirection or retrieving the redirected URL in my tests?"

12 replies

Hey @superai.

Can u elaborate ur issue more precisely

.aleksandaraleksandrov
.aleksandaraleksandrov

I have seen that or something like that in my tests. My url assertions were getting wrong data. If that is the case, try adding waits before or after the assert. This helped my cases.

kieuminhnhat
kieuminhnhat

Anyone have solution?

It really needs details on the problem for there to be a solution

kieuminhnhat
kieuminhnhat

For example I'm in page A, then I click button to direct to page B. then I want to get page B link by page.url, but the result is showing page A URL

I don't know what is the problem> I already set the wait function and make sure it is loaded to page B

Which wait function are you using, are you just using a timeout, or waiting for a specific response/verifying that it's actually page B that is loaded?

kieuminhnhat
kieuminhnhat

page.wait_for_url(r".submitted.") print(f"page URL: {page.url}")

but it is never print the destination URL , the URL should have the submitted text on it.

kieuminhnhat
kieuminhnhat
CleanShot_2024-03-28_at_20.32.052x.jpg

https://playwright.dev/docs/navigations#navigation-events

Not sure if I'm reading that right but it sounds like the Navigation occurs first, which will change the page url, but page.url() only returns the new page url in the Loading stage

Could be worth trying to verify that the Navigation has occurred in a different way

kieuminhnhat
kieuminhnhat

Thanks you, I will look into it

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.