RE: Getting Exception in alert

I am getting below exception while handling alert in my test:

Exception in thread “main” org.openqa.selenium.UnhandledAlertException: Unexpected modal dialog

I am using below code:

try {

.implicitlyWait(280, TimeUnit.SECONDS);
Alert alt = driver.switchTo().alert();

actualBoxtitle = alt.getText(); // get content of the Alter

System.out.println(actualBoxtitle); // Message

if (actualBoxtitle.contains(“User or Password is not valid”)) { // Compare

System.out.println(“Test case SS[” + i + “]: Failed”);
} catch (NoAlertPresentException Ex) {

System.out.println(“Test case SS[” + i + “]: Passed”);

Please help me out.

Add Comment
3 Answers

Hi Virender,

Thanks for your help. Actually I have debugged the code and found exception  coming at below line:

“Alert alt = driver.switchTo().alert();”

If I will use explicit wait instead of implicit wait. Will it work?
Please suggest.


Default Answered on April 24, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.