📜  selenium 面试问题 - 任何代码示例

📅  最后修改于: 2022-03-11 14:57:34.585000             🧑  作者: Mango

代码示例6
How to switch between multiple windows in Selenium?
Ans. Selenium has driver.getWindowHandles() and driver.switchTo().window(“{windowHandleName}”) commands to work with multiple windows.

The getWindowHandles() command returns a list of ids corresponding to each window and on passing a particular window handle to the driver.switchTo().window(“{windowHandleName}”) command, we can switch control/focus to that particular window.

for (String windowHandle : driver.getWindowHandles()) {
     driver.switchTo().window(handle);
}