How to handle Alerts in Selenium

Will use switchTo() method. Please check the below scenarios.

      • void dismiss() // To click on the ‘Cancel’ button of the alert.

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

      • void accept() // To click on the ‘OK’ button of the alert.

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

      • String getText() // To capture the alert message.

driver.switchTo().alert().getText();

      • void sendKeys(String stringToSend) // To send some data to alert box.

driver.switchTo().alert().sendKeys(“Text”);

Default Asked on May 4, 2018 in Software Testing.
Add Comment
  • 0 Answer(s)
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.