views:

840

answers:

4

I get this error while running selenium RC tests against IE7.

com.thoughtworks.selenium.SeleniumException: ERROR: There was an unexpected Alert! [error:[object Error]]

It happens whenever I attempt to click a link or a tab or anything clickable. Any Ideas guys. This is really frustrating.

+2  A: 

Checking the Google search results for your error message, and the selenium development mailing list, it sounds as if this is not a bug in Selenium but rather it is Selenium telling you that an unexpected window.alert() function was called in your web application, and that Selenium does not know how to handle it because you did not tell it how to.

matt b
A: 

I'd be surprised if the same issue isn't occurring in other browsers. Perhaps your application behaves differently depending on the browser? Basically Selenium is reporting that it can't move onto further commands after you are clicking on these links or tabs because it has detected an unexpected JavaScript alert. You wont see these alerts because Selenium consumes them. There are a few things you can do to work out what's going on.

The first thing I'd suggest is to just check your application in IE7. Manually complete the steps of your tests - do you see the JavaScript alerts? If so, you will need to add the appropriate commands to your Selenium test.

If for some reason you can't replicate the alerts manually you can either dismiss the alert by using the the getAlert command, or use the response from getAlert to find out the text of the unexpected alert.

Java/TestNG example for finding out the message of the alert:

assertEquals(selenium.getAlert(), "Hello World");

The above will still cause your test to fail (unless the alert really does say 'Hello World'), but will fail with a message similar to "expected 'Hello World' but was 'Your unexpected alert message'".

Dave Hunt
A: 

I'm seeing the same error. Normally we run our test using C#, but in this case we are setting up some simple tests using the Selenium IDE.

Since Selenium IDE records your events and then allows you to play them back you would expect it to handle the alert. When looking at the events it records it appears it's capturing the alert. However, when you play it back the events are out of order.

First it captures the click event. Then is uses assertAlert to make sure the alert happened.

The problem occurs when you play it back. It does the click event and then errors out. If you move the assertAlert statement before the click event it doesn't work. If you change the assertAlert to waitForAlert that doesn't work either. I can't seem to figure out anyway to get the playback working in the Selenium IDE. If I didn't need this runnable for a non-techy I'd just put it into my regular tests and be done with it.

Edit: After further review it appears the alert message isn't matching. Even though it grabbed the alert itself when doing the record. Visual inspection doesn't do anything to help me determine what it considers different.

Altonymous
`storeAlert(dummy_variable)` before `click()` seems to work best for me.
Kev
A: 

I'm getting a similar thing.
No error in IE, JS error popup in Chrome, nothing in FF...until I run my Selenium script and it reports an unexpected error. Amusingly when I do selenium.IsAlertPresent() it returns false, even though it says there was one.

DazManCat