标签:handlers rom button frame strong drive pup pts before
5. 弹出窗口 popup window
//使用driver.switchTo()可以进行Windows, Frames, Alerts, Confirms, Prompts之间的切换
driver.switchTo().window("windowhandle");
driver.switchTo().frame("framename");
driver.switchTo().alert();
6. 切换到新的Window(import java.util.Set;)
//1. 保存之前的Windows Handles
Set<String> beforeHandlers = driver.getWindowHandles();
String beforeHandler = beforeHandlers.iterator().next();
// 2. 执行弹出新窗口的操作
WebElement KButton = driver.findElement(By.name("OK"));
OKButton.click();
//3. 保存现在的Windows Handles
Set<String> afterHandlers = driver.getWindowHandles();
//4. 从现在的Windows Handles中remove调之前的,就能得到刚弹出新窗口的window handle
afterHandlers.removeAll(beforeHandlers);
String newWinhandler = afterHandlers.iterator().next();
//5. 切换到新弹出的窗口
driver.switchTo().window(newWinhandler);
//6. 返回之前的窗口
driver.switchTo().window(beforeHandler);
标签:handlers rom button frame strong drive pup pts before
原文地址:http://www.cnblogs.com/meimeilove/p/Selenium.html