Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

page.url() not getting current url immediately #4684

Closed
HilaryGreen opened this issue Dec 11, 2020 · 3 comments
Closed

page.url() not getting current url immediately #4684

HilaryGreen opened this issue Dec 11, 2020 · 3 comments

Comments

@HilaryGreen
Copy link

HilaryGreen commented Dec 11, 2020

I have an Angular SPA application for testing where there are a row of top navigation tabs. If I click on the tab I may get different responses, depending on the tab. One just goes back to the homepage, with display of the page but with no api calls and changing the url to /home.. Another goes to the search page, which displays the page, fetches the default data both using api calls and changing the url to /search. one goes to the data (entry) page, which displays the page using api calls, but fetches no default data, then changes the url to /data.

I do not know exactly when in the process the url is changed or how, just that await page.url() does not get the right url (it gets the one before the navigation. However if I wait about 500ms, page.url() returns the right url. I have tried waitForNavigation() but this does not seem to work as it does not recognise a navigation. And waitForLoadState('networkidle') does not help either.

Do you have an idea what is going on and why the current url is not found without a hard wait? Is there anything that might be done to by the application developers which might improve the behaviour?

Playwright 1.6.2
Angular 9 or 10

@pavelfeldman
Copy link
Member

If url changes, be it through navigation or the history API, waitForNavigation should handle your use case. See https://github.com/microsoft/playwright/blob/master/docs/navigations.md#asynchronous-navigation

@itsMGA
Copy link

itsMGA commented Jan 16, 2023

WHy is this closed with a 404 not found, how is this relevant for someone who uses python instead of js?

@ltsuda
Copy link
Contributor

ltsuda commented Jan 16, 2023

Please, see if this helps. I'm just adding the online documentation that Pavel sent.

Python
https://playwright.dev/python/docs/navigations#asynchronous-navigation
JS/TS
https://playwright.dev/docs/navigations#asynchronous-navigation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants