Unable to close modal dialog webdriver - org.openqa.selenium.unhandledalertexception modal dialog present



There are times when you are not able to close a simple modal dialog in IE/Firefox
Mostly an error stating "org.openqa.selenium.unhandledalertexception modal dialog present"

Solutions:

These might not work:

Alert alerts = driver.switchTo().alert();

alerts.accept()
alerts.dismiss()
Since this works only for alerts.

driver.switchTo().window()

this method to a window with know name.

Alternative:


Actions action = new Actions(driver);
action.sendKeys(Keys.ESCAPE);

  
These might work:

"webdriver.getwindowHandles()" - to obtain a list of know windows. you may pass the handle to
"switchto().window()"

windowids = driver.getWindowHandles();

iter= windowids.iterator();
String mainWindowId=iter.next();
String popupWindowId=iter.next();
driver.switchTo().window(popupwindowid);


Alternative:

String mainhndl = driver.getWindowHandle();

//Code that brings up the popup
Set handles = driver.getWindowHandles();

for(String handle: handles)
{
  If(!mainhndl.equals(handle))
  {
     WebDriver popup = driver.switchTo().window(handle);
      popup.close();
  }
}



Comments

Popular posts from this blog

Software Testing @ Microsoft

Trim / Remove spaces in Xpath?