1. 程式人生 > >Java Selenium - 處理頁面彈出窗

Java Selenium - 處理頁面彈出窗

cnblogs clas java iterator 循環 當前 iter string ren

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); }

  

Java Selenium - 處理頁面彈出窗