String parentWindowHandler = browser.getWindowHandle(); // Store your parent window
System.out.println(parentWindowHandler);
browser.findElement(By.cssSelector("button.btn-danger")).click();
String subWindowHandler = null;
Set<String> handles = browser.getWindowHandles(); // get all window handles
Iterator<String> iterator = handles.iterator();
while (iterator.hasNext()){
subWindowHandler = iterator.next();
}
browser.switchTo().window(subWindowHandler);
System.out.println(subWindowHandler);// switch to popup window
答案 0 :(得分:-1)
集合顶部的迭代器。当您到iterator.next()
时,它将只是您的父窗口。如果您想要获取子窗口句柄,请执行更多iterator.next()
while (iterator.hasNext()){
parentWindowHandler = iterator.next();
subWindowHandler = iterator.next();
}