This Method will Solve Your Problem:
private void handleWindow() {
try {
String parent = driver.getWindowHandle();
Set<String> pops=driver.getWindowHandles();
{
Iterator<String> it =pops.iterator();
while (it.hasNext()) {
String popupHandle=it.next().toString();
if(!popupHandle.contains(parent))
{
driver.switchTo().window(popupHandle);
System.out.println("Popu Up Title: "+ driver.switchTo().window(popupHandle).getTitle());
driver.close();
driver.switchTo().window(parent); // control is moving to parent window
}
}
}
} catch (NoAlertPresentException e) {
e.printStackTrace();
}
}
No comments:
Post a Comment