Explain me how to Handle Alerts in Selenium WebDriver?

Submitted by: Muhammad
Here are a few methods of Alerts handling which are widely used in Selenium Webdriver.

☛ void dismiss() is used to click on the 'Cancel' button of the alert.
☛ driver.switchTo().alert().dismiss();
☛ void accept() is used to click on the 'OK' button of the alert.
☛ driver.switchTo().alert().accept();
☛ String getText() is used to capture the alert message.
☛ driver.switchTo().alert().getText();
☛ void sendKeys(String stringToSend) is used to send some data to alert box.
☛ driver.switchTo().alert().sendKeys("Text");
Submitted by: Muhammad

Read Online Automation Job Interview Questions And Answers