padmakumar padmakumar - 1 year ago 95
Java Question

why selenium.isConfirmationPresent() returns true after using chooseCancelOnNextConfirmation

I am having a code like the following

selenium.chooseCancelOnNextConfirmation();"deleteRequest");// confirm dialog will be displayed on clicking the button

System.out.println("is confirmation present "+selenium.isConfirmationPresent());

Eventhough i am using selenium.chooseCancelOnNextConfirmation(), please let me know why selenium.isConfirmationPresent() returns true.

But selenium.isConfirmationPresent() returns false after


Is it mandatory to use selenium.getConfirmation(), as i am not able to do further processing. It says

com.thoughtworks.selenium.SeleniumException: ERROR: There was an unexpected Confirmation! [Are you sure to delete selected request(s)?]
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(

Answer Source

This is the expected behaviour. chooseCancelOnNextConfirmation() dictates the behaviour of getConfirmation(). Calling getConfirmation() effectively "consumes" the confirmation popup. You must use getConfirmation or verifyConfirmation before continuing your test, as any other Selenium command will fail if you do not handle the popup with a getConfirmation call.

By default, the confirm function will return true, having the same effect as manually clicking OK. This can be changed by prior execution of the chooseCancelOnNextConfirmation command. If an confirmation is generated but you do not get/verify it, the next Selenium action will fail.

So your code could be:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download