Handling Web Alerts
Alert is a pop-up window that comes up on the screen. There are many user actions that can result in an alert on the screen. For e.g. user clicked on a button that displayed a message or maybe when you entered a form, the HTML page asked you for some extra information.
Alerts are different from regular windows. The main difference is that alerts are blocking in nature. They will not allow any action on the underlying webpage if they are present. So if an alert is present on the webpage and you try to access any of the elements in the underlying page you will get an exception.
Types of Alerts
There are basically three types of alert:
Handling alerts using Selenium WebDriver
Selenium provides us with an interface called Alert. It is present in the org.openqa.selenium.Alert package. Alert interface gives us the following methods to deal with the alert:
accept() To accept the alert
dismiss() To dismiss the alert
getText() To get the text of the alert
sendKeys() To write some text to the alert
alert("This is a simple alert");
var popuResult = confirm("Confirm pop up with OK and Cancel button");
var person = prompt("Do you like toolsqa?", "Yes/No");