Playwright Java url() method returns URL of previous page

160 Views Asked by At

I my test I navigiate from PageA to PageB throught locator click, After click I try to get url via page.url(), which returned url of PageA.

For now solution I could achieve was page.reload().url(), which really returned right URL. (no any wait can help here, the page object just does not fetch latest url)

What can i do in this situation to avoid reload?

1

There are 1 best solutions below

0
On

Use waitForURL.

As it waits for the main frame to navigate to the given URL.

page.click("a.delayed-navigation"); // Clicking the link will indirectly cause a navigation
page.waitForURL("**/target.html");