Skip to main content

switchWindow

Overview

Use the switchWindow command to focus on a specific tab or window.

Usage

await browser.switchWindow(urlOrTitleToMatch);

Command Parameters

NameTypeDescription
urlOrTitleToMatchString or RegExpA string or regular expression matching the page's title or URL.

Usage Examples

it("should switch to another window", async ({ browser }) => {
// open URL
await browser.url("https://google.com");

// create a new window
await browser.newWindow("https://webdriver.io");

// switch back by matching the URL
await browser.switchWindow("google.com");

// switch again by matching the page title
await browser.switchWindow("Next-gen browser and mobile automation test framework for Node.js");
});

References

We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.