Notifications
Clear all

[Solved] Selenium: how to manage browser's popup window

4 Posts
3 Users
6 Reactions
806 Views
3
Topic starter

how to handle browser’s popup window (for example in case of executing exec state machine action through UI)?

 image 1
2 Answers
4
Topic starter

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);
}
jmyers 2012-06-14 10:06:00

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.

jmyers 2012-06-14 11:06:00

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().

0

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.