Skip to main content

switchWindow

Switch focus to a particular tab / window (Classic sessions).

In a WebDriver BiDi session this command throws. browser.url() and browser.newWindow() return the browsing context, and browser.browsingContexts() lists the open top-level contexts. Commands run on the context you hold.

Usage​

await browser.switchWindow(matcher)

Parameters​

NameTypeDetails
matcherString, RegExpString or regular expression that matches either the page title or URL, the window name, or the window handle

Example​

switchWindow.js
it('should switch to another window', async () => {
// Classic
await browser.url('https://google.com')
const handle = await browser.getWindowHandle()
await browser.newWindow('https://webdriver.io')
await browser.switchWindow('google.com')
await browser.switchWindow(handle)

// BiDi
const google = await browser.url('https://google.com')
const docs = await browser.newWindow('https://webdriver.io')
console.log(await docs.getTitle())
console.log(await google.getTitle())
});

Welcome! How can I help?

WebdriverIO AI Copilot