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​
| Name | Type | Details |
|---|---|---|
url | string | the URL to navigate to, absolute or relative to baseUrl |
optionsoptional | UrlCommandOptions | navigation options, the same as for browser.url() |
options.waitoptional | string | the readiness to wait for: none, interactive, complete (default) or networkIdle |
options.timeoutoptional | number | how long to wait for the page to load, in milliseconds |
options.onBeforeLoadoptional | Function | a function that runs in the page before its own scripts |
options.authoptional | Object | basic authentication credentials, { user, pass } |
options.headersoptional | Object | headers 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