切换窗口
将焦点切换到特定的标签页/窗口。
用法
browser.switchWindow(matcher)
参数
名称 | 类型 | 详情 |
---|---|---|
matcher | String, RegExp | 匹配页面标题或URL、窗口名称或窗口句柄的字符串或正则表达式 |
示例
switchWindow.js
it('should switch to another window', async () => {
// open url
await browser.url('https://google.com')
// get window handle
const handle = await browser.getWindowHandle()
// 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')
// switch back via window handle
await browser.switchWindow(handle)
});