Supponendo che l'aspettativa è solo andare a essere due finestre popping up (uno dei genitori e uno per il pop-up), poi basta aspettare due finestre per uscire, trovare l'altra maniglia della finestra e passare ad essa.
WebElement link = // element that will showModalDialog()
// Click on the link, but don't wait for the document to finish
final JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript(
"var el=arguments[0]; setTimeout(function() { el.click(); }, 100);",
link);
// wait for there to be two windows and choose the one that is
// not the original window
final String parentWindowHandle = driver.getWindowHandle();
new WebDriverWait(driver, 60, 1000)
.until(new Function<WebDriver, Boolean>() {
@Override
public Boolean apply(final WebDriver driver) {
final String[] windowHandles =
driver.getWindowHandles().toArray(new String[0]);
if (windowHandles.length != 2) {
return false;
}
if (windowHandles[0].equals(parentWindowHandle)) {
driver.switchTo().window(windowHandles[1]);
} else {
driver.switchTo().window(windowHandles[0]);
}
return true;
}
});
fonte
2014-03-19 17:52:35
Verificare sul link qui sotto per una migliore comprensione di come gestire le finestre di dialogo modali o pop up utilizzando selenium2.0 http://www.thoughtworks-studios.com/twist/2.3/help/how_do_i_handle_popup_in_selenium2.html – Hemanth