Sign up ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

How do I solve the Unhandled exception: Modal dialog present.

Below is error line.

1) test(TestCases1.ComparePage)org.openqa.selenium.UnhandledAlertException: Modal dialog present: Please retain at least 2 products to compare
Build info: version: '2.40.0', revision: 'fbe29a9', time: '2014-02-19 20:55:11'
System info: host: 'soft-02', ip: '', 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_16'
Session ID: 8aaadb53-1572-42c4-abe7-417e0d59c676
Driver info: org.openqa.selenium.firefox.FirefoxDriver

I am testing a web application eCommerce site. When I select three items to remove from compare list, it will display the alert pop message, then I use alert class and accept the pop up and other scenarios, but my code is not handling alert pop up, and it will close the driver. Here is my code, not working

Alert al = Driver.driver.switchTo().alert(); 
    else al.dismiss();
share|improve this question

2 Answers 2

You are either trying to access an element that the FirefoxDriver can't reach to because the modal dialogue is still active or (looking at the log) you are clicking "Ok/Done/Finished/Whatever" on the modal dialogue without selecting the required number of products.

share|improve this answer

Since you didn't provide much information about what you're testing, I'd have to conclude that your site is popping up a modal dialogue box that reads "Please retain at least 2 products to compare." Under what conditions does your site do that? Have you accidentally triggered them? Are you controlling for how many options are on the compare site so that when you remove the three options, there are still at least 2 left? It seems like you're comparing 4 options and trying to remove 3 of them. You should confirm that the application is working according to spec; again, it seems like it's popping up an error message, which, if it should be doing that, you should be verifying.

In other words, it sounds like this test case has some serious issues and should be re-examined at an abstract level, not just the test code.

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.