padmakumar
padmakumar

Reputation: 61

why selenium.isConfirmationPresent() returns true after using chooseCancelOnNextConfirmation

I am having a code like the following

selenium.chooseCancelOnNextConfirmation();

selenium.click("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

selenium.getConfirmation();

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)?] com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97) at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:9

Upvotes: 0

Views: 3033

Answers (1)

Paul Andrew
Paul Andrew

Reputation: 525

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:

selenium.chooseCancelOnNextConfirmation();

selenium.click("deleteRequest")

selenium.getConfirmation();

Upvotes: 2

Related Questions