Skip to main content

navigate

Navigate this browsing context to a URL and wait until the page has loaded. It works for a tab, a window or a frame. Only this context navigates: other tabs keep their page, and the parents of a frame stay where they are.

browser.url() always navigates the session's first top-level browsing context, so use navigate() for any other one. It takes the same options as browser.url(), and a relative URL resolves against the baseUrl option. Returns this context, with url and request updated.

Usage​

const context = await browser.url('https://webdriver.io')
await context.navigate(url, { wait, timeout, onBeforeLoad, auth, headers })

Parameters​

NameTypeDetails
urlstringthe URL to navigate to, absolute or relative to baseUrl
options
optional
UrlCommandOptionsnavigation options, the same as for browser.url()
options.wait
optional
stringthe readiness to wait for: none, interactive, complete (default) or networkIdle
options.timeout
optional
numberhow long to wait for the page to load, in milliseconds
options.onBeforeLoad
optional
Functiona function that runs in the page before its own scripts
options.auth
optional
Objectbasic authentication credentials, { user, pass }
options.headers
optional
Objectheaders to send with the request

Example​

navigate.js
it('navigates one tab without touching the other', async () => {
const page = await browser.url('https://webdriver.io')
const tab = await browser.newWindow('https://webdriver.io', { type: 'tab' })

await tab.navigate('https://webdriver.io/docs/api', { wait: 'interactive' })
console.log(tab.url) // outputs: "https://webdriver.io/docs/api"
console.log(await page.getUrl()) // outputs: "https://webdriver.io/"
})

Returns​

  • <WebdriverIO.BrowsingContext> return: this browsing context

Welcome! How can I help?

WebdriverIO AI Copilot