how to handle browser’s popup window (for example in case of executing exec state machine action through UI)?
By Inderpal:
For struts based popup window, you can handle using following way:
String curHandle = tab.getDriver().getWindowHandle();
try {
Set<String> handles = new HashSet<String>(tab.getDriver().getWindowHandles());
handles.remove(curHandle);
tab.getDriver().switchTo().window(handles.iterator().next());
context.waitUntilElementExists(By.tagName("input"));
Window window = new Window(context, tab.getDriver().findElement(By.tagName("body")));
//Your code here
//WebElement roleNameField = window.getEl().findElement(By.name("Name"));
System.out.println("done");
}
finally {
tab.getDriver().switchTo().window(curHandle);
}
If you're working in IE (may be the case for other browsers as well), you may need to go to Internet Options -> Security and uncheck 'Enable Protected Mode' for one or all of Internet, Local Intranet, Trusted Sites.
Also, after leaving the popup, if switching back to the browser window, your context will be set to the defaultContext window.top. If you were originally working in a tab within the browser (tabs are in their own iframe), you will need to change this using tab.switchDriver().
The Protected Mode settings should be same for all zone. In our case it should be strictly OFF for all zone to support struts based pop-up screens. This will resolve “Unable to get browser” error if you are seeing that.