Handling different types of alerts & user authentication in selenium

Alerts are basically popup box that takes the focus away from the current browser screen and forces you to read the alert message and do some action,
Once you take any action (accept or dismiss), it allows to resume performing the task on browser.

There are basically 3 types of alerts
Alert box, Confirm box, and Prompt box.

We will see how to handle each of these diff types of alerts in selenium

A simple alert:

in this either you can accept or dismiss an alert

Prompt alert

Here we can enter text in alert textbox, check the checkboxes and can accept / dismiss…

Username and password alert

uname_pwdalerts

Some sites pops up alerts to enter username and password, these fields can’t be identified by browser locators (plugins such as firebug for ff or F12 for IE),in this case we can pass the username and password while launching the browser,

Simple solution is to pass username and password while launching browser.

Confirm alert

Either you can accept and dismiss the alert, if u click on “prevent this from…” checkbox, you won’t get the alert again for that browser instance…
This below code even explains, the usage of Robot class in selenium.

Chose proper alert handling method from above, and handle alerts from your testing site.
Short links – bit.ly/qav-selalerts

Content posted is based on learning or working experience, please leave comments if anything needs to be added or updated, discuss your queries on our facebook:qavalidation.com, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: