TesterHQ - The Evil Tester Blog Aggregator

Oct 2, 2013 - 2 minute read - FAQ Selenium Simplified Blog

FAQ: Why Does Selenium Not Work With This Alert?

Original Blog Posting on [SeleniumSimplified.com]

I received another question about Alerts this morning.

I receive this question frequently enough that I should consider it an FAQ.

So “Why does Selenium not work with my Alert?” or “Why can’t Selenium handle the alert in my application?”

There is an FAQ answer on the Selenium wiki that shows the Alerts API

But that typically doesn’t answer the question because the person asking the question has used the alerts API.

The answer I have given, in every single instance, takes the form “The thing you think is an alert, is not an alert”

The use of the web has changed. HTML has changed. We can now style div elements to look like dialogs and alerts, we can even give them focus and make them modal. That doesn’t mean they fit the definition of an Alert. i.e. something triggered by the JavaScript methods: alert, confirm or prompt


The following are examples of alerts:

With any of the above examples, try and “inspect element” on the alert. You can’t. Because it is an alert.

The following examples are not alerts:

For each of the above, try and “inspect element” and you can. Because it is an HTML div, not an alert.

Live Examples of pseudo-alerts include:

  • those horrible “welcome to our website for the first time will you take our survey about our web site” dialogs
  • “you need to be logged in to see this content” overlays
  • “sign up for my mailing list and I’ll let you see what you came here for” overlay
  • “tweet this and then I’ll let you read it” overlay

Only use the Alert API on things that are Alerts. If you are using the Alert API, and it isn’t working, then the thing you are testing might not be an Alert.