switchWindow
Switch focus to a particular tab / window.
Usage
browser.switchWindow(matcher)
Parameters
| Name | Type | Details | 
|---|---|---|
| matcher | String,RegExp | String or regular expression that matches the title and url of the page or window name | 
Example
- Asynchronous Mode
- Synchronous Mode
switchWindow.js
it('should switch to another window', async () => {
    // open url
    await browser.url('https://google.com')
    // create new window
    await browser.newWindow('https://webdriver.io')
    // switch back via url match
    await browser.switchWindow('google.com')
    // switch back via title match
    await browser.switchWindow('Next-gen browser and mobile automation test framework for Node.js')
});
switchWindow.js
it('should switch to another window', () => {
    // open url
    browser.url('https://google.com')
    // create new window
    browser.newWindow('https://webdriver.io')
    // switch back via url match
    browser.switchWindow('google.com')
    // switch back via title match
    browser.switchWindow('Next-gen browser and mobile automation test framework for Node.js')
});
caution
Synchronous Mode will depcrecated with Node.js v16. With an update to the underlying Chromium version it became technically impossible to provide the same synchronous behavior. We recommend to start transition to asynchronous command execution. For more information, see our RFC.