Skip to main content

getUrl

Get the URL of the document shown in this browsing context, read from the page. It also updates the url property, which otherwise holds the URL the context was last navigated to and does not follow navigations the page did itself.

Usage​

const context = await browser.url('https://webdriver.io')
await context.getUrl()

Example​

getUrl.js
it('reads the url after the page changed it', async () => {
const page = await browser.url('https://webdriver.io')
await page.execute(() => history.pushState({}, '', '/docs/api'))

console.log(page.url) // outputs: "https://webdriver.io", the url it was navigated to
console.log(await page.getUrl()) // outputs: "https://webdriver.io/docs/api"
console.log(page.url) // outputs: "https://webdriver.io/docs/api"
})

Returns​

  • <string> return: the document URL

Welcome! How can I help?

WebdriverIO AI Copilot