tejas
tejas

Reputation: 67

How to handle alert on firefox 10

Page-1 ScreenshotI m using firefox 10 and selenium-server-standalone-2.25.0.jar . I am writing script using webdriver only. In my application there is one alert box with OK button. I try many code solution but does not work. Following are workarounds that i tried

Solution 1:

((JavascriptExecutor)driver).executeScript("window.alert = function(msg){};");

Solution 2:

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

page 2 screenshot But It displays below error

Caused by: org.openqa.selenium.UnhandledAlertException: Modal dialog present
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
java.lang.reflect.Constructor.newInstance(Unknown Source)

Upvotes: 0

Views: 766

Answers (1)

Ioan
Ioan

Reputation: 5187

I suggest you the following solutions :

  • If the code says that there is still another dialog after you click ok on the first one, try to do one more time : driver.switchTo().alert().dismiss();
  • Check default wait timing for elements to appear (it should be at least 1 second)
  • If does not work, try to handle this part of this code within a try-catch, catching UnhandledAlertException exception and try to dismiss() in the catch code.
  • It is the first time you have problems with this version of Firefox? I am using Firefox 13.0.1 because I had lots of problems with other versions, maybe you should reconsider an upgrade.

Tell me if something was useful for you

Upvotes: 2

Related Questions