How to Handle Alert window in Selenium Webdriver

asked 3 months ago

Alerts are small message boxes that appear on the screen to provide users with information, warnings, or prompts for confirmation. They are often used to display messages, request permission to perform certain actions, or warn users about potential consequences.

Go to - > https://www.qafeast.com/demo - > Click Context Menu - > Right click at Right hand side

 

alertwindow_seleniumjava

 

The alert pop up appears, the selenium webdriver provides the methods to handle the alert window.

To accept the alert popup

driver.switchTo().alert().accept();

 

To dismiss the alert popup

driver.switchTo().alert().dismiss();

 

To get the text in the alert popup

String alertText = driver.switchTo().alert().getText();
System.out.println(alertText);
 

 

To fill the text in the alert pop up

driver.switchTo().alert().sendKeys("Texttofill");