Automation Question:
Explain me how to Handle Alerts in Selenium WebDriver?

Answer:
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");
☛ 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");
Previous Question | Next Question |
Tell us what is the difference between @Factory and @DataProvider annotation? | Explain me how to execute JavaScript in Selenium? |