# 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[​](#usage "Direct link to Usage")

```
await browser.switchWindow(matcher)
```

## Parameters[​](#parameters "Direct link to Parameters")

| Name      | Type             | Details                                                                                                       |
| --------- | ---------------- | ------------------------------------------------------------------------------------------------------------- |
| `matcher` | `String, RegExp` | String or regular expression that matches either the page title or URL, the window name, or the window handle |

## Example[​](#example "Direct link to 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())

});
```
