2

Trying to use the ieDriver.switchTo().window(windowHandle) method to switch to a popup window but my test script stops and does not proceed.

When I close the window manually i get the error

org.openqa.selenium.NoSuchWindowException: Unable to get browser

I know the window exists because I used the ieDriver.getWindowHandles() method to retrieve it.

All my protected mode settings are the same, I even tried to use the 'INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS' technique to no avail. Any other suggestions?

I'm running selenium 2.32.0 with IE9 on a Windows 7 machine.

Nunser
  • 4,512
  • 8
  • 25
  • 37
Mike Kistler
  • 21
  • 1
  • 2
  • How is the popup created? – Arran Jun 17 '13 at 14:14
  • Can you show the code where `windowHandle` is created – Dingredient Jun 17 '13 at 15:33
  • Have you tried another way of solving this? Maybe pressing ALT+TAB will get you the desired result. I could have helped you in Ruby but I dunno anything about Java. Just proposing a different kind of solution.. – Xwris Stoixeia Jun 17 '13 at 16:14
  • I had the same experience, [here](http://stackoverflow.com/questions/19003003/check-if-any-alert-exists-using-selenium-with-python?answertab=active#tab-top) is the solution. It's written in python, hope you can convert codes. – Zeinab Abbasimazar Oct 22 '13 at 10:33

3 Answers3

1

Above code isfor handling window pops. If you want to handle javascript popups like alerts, or confrmation popup, you need to use

driver.SwitchTo.alert().accept();

or

driver.SwitchTo.alert().dismiss();

hope it'll help you

Shammi
  • 203
  • 2
  • 4
  • 8
0

maybe the popup is generated, with iframe, then you have to use switchTo.frame();

buddy
  • 183
  • 6
0

You should do something like:

  WebDriverWait webDriverWait= new WebDriverWait(driver, 5000);
  webDriverWait.until(ExpectedConditions.alertIsPresent());
  driver.switchTo().alert().accept();

First you will initialize a WebDriverWait object that will allow you to wait until some condition is met, in this case - alert is present. Then, the driver will be switched to this alert,

Johnny
  • 14,397
  • 15
  • 77
  • 118