There are two types
of alerts those needs to be handle while automation:
1. Windows based alert pop ups:
As we know that handling windows based pop ups is beyond
WebDriver’s capabilities,
thus we require some third party tool to handle the windows
based alerts pop-ups.For ex: AutoIT.
2. Web based alert pop ups:
Since,web based popups or JavaScript popups are generated by
web application, hence they can be easily handled by selenium.
We can handle these alerts as below:
Alert alert = driver.switchTo().alert();
Where Alert is an interface. Below methods can be used as
per the requirement:
//For accepting the alert or clicking on OK button.
alert.accept();
// To reject the alert or to click on Cancel button.
alert.dismiss();
//to get the text which is present on th Alert.
alert.getText();
//to pass the text to the prompt popup
alert.sendkeys();
//To Authenticate by passing the credentials
alert.authenticateUsing(Credentials credentials)