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 {

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

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

alt.accept();
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

Hey Rohit,

It becomes very specific now, could you share with us the URL?

Can you tell me what type of Alert you are getting, compare it with top three buttons here

http://www.toolsqa.com/automation-practice-switch-windows/

virender

Professor Answered on April 24, 2015.
Add Comment

Your Answer

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