17

I have a button that displays Javascript confirmation popup. This is a part of my test case:

<tr>
    <td>clickAndWait</td>
    <td>buttonId</td>
    <td></td>
</tr>
<tr>
    <td>verifyTextPresent</td>
    <td>Object has been deleted</td>
    <td></td>
</tr>

It works as expected: OK is clicked automatically on a popup and verifyTextPresent return true. Still, I get [error] There was an unexpected Confirmation! in the log and test case fails.

Any suggestions?

Ula Krukar
  • 12,549
  • 20
  • 51
  • 65
  • what do you mean by "javascript confirmation popup" > an alert? a confirm? a custom dialog window? a pop-up window? – Bozho Jan 14 '10 at 08:33

4 Answers4

24

Summary: In the IDE use storeConfirmation.

You have to consume confirmation dialogs. Otherwise the Selenium test will fail.

From the Java Selenium RC API Selenium.html.getConfirmation method:

If a confirmation is generated but you do not consume it with getConfirmation method, the next Selenium action will fail.

Edit:

storeConfirmation consumes the confirmation as well.

storeConfirmation ( variableName )

Retrieves the message of a JavaScript confirmation dialog generated during the previous action.

If a confirmation is generated but you do not consume it with getConfirmation method, the next Selenium action will fail.

Community
  • 1
  • 1
Thomas Jung
  • 32,428
  • 9
  • 84
  • 114
8

I encountered the same problem, and I solved it like this:

chooseOkOnNextConfirmation click buttonId assertConfirmation

This makes my test run green in my Selenium IDE.

The code to do this is:

<tr>
    <td>chooseOkOnNextConfirmation</td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>ctl00_CPHMain_ucFormDMS_grdDocumentList_ctl00_ctl04_btnDelete</td>
    <td></td>
</tr>
<tr>
    <td>assertConfirmation</td>
    <td>Areyousureyouwanttodeletethisdocument?</td>
    <td></td>
</tr>
Andrew Hancox
  • 2,330
  • 1
  • 20
  • 28
Knubo
  • 8,333
  • 4
  • 19
  • 25
1

using selenium.chooseOkOnNextConfirmation is correct but insead of using this alone use

selenium.click("xpath=//button"); selenium.getConfirmation(); selenium.chooseOkOnNextConfirmation(); Here it will first click on the button and get the confirmation , then it would click OK from that confirmation

0

In Selenium IDE you can use waitForConfirmation(pattern)