Java Selenium - 处理页面弹出窗

时间:2024-06-19 12:04:26

1. 得到当前窗口句柄

2. 得到所有窗口句柄

3. 循环找到目标窗口

String currentWindow = driver.getWindowHandle();

Set<String> handles = driver.getWindowHandles();
Iterator<String> it = handles.iterator();
while (it.hasNext())
{
String handle = it.next();
if (currentWindow.equals(handle))
  continue;
WebDriver window = driver.switchTo().window(handle);
}