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?”
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 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.