In Playwright, we can get the current page URL Using the url() method linked with page instance.
Table of Contents
Syntax
page.url()
Example
test.only('Get Current URL', async({page}) =>{
await page.goto('https://www.programsbuzz.com')
await page.locator("li.we-mega-menu-li>a[href='/about-us-programsbuzz']").click()
console.log(page.url())
})
Once you get the URL, you may want to assert the URL; for that, a different method exists; refer Verify URL in Playwright.
Also, sometimes client-side router doesn't immediately change the URL after clicking on the button or any other element that triggers the navigation. In that case, you can use waitForURL() method.