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


The only way to get the solution is to see the more of the stack trace of the exception. Also, instead of accept try to dismiss the alert. There might be a possibility that alert as no default accept method.

Also, it seems that exception is not coming in this code, it might be coming after the code. It would be helpful if you point out on which line the exception came.

Please be as elaborate as possible in explaing the question, just by looking at code its hard to find the cause of exception.


Professor Answered on April 24, 2015.
Add Comment

Your Answer

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