Alerts are tiny pop-up windows or boxes that show messages or notifications and ask the user for permission to perform specific types of operations in exchange for some information. They can also be used as warning techniques.
The alert "okay cancel" popup in Selenium, is a tiny message box that shows up on the screen to provide information or request authorization before carrying out an operation.
The majority of the time, when we fill out a form and click the submit button, the message "phone number is necessary" pops up or we neglect to tick the box for the terms and conditions. Once I have filled all the mandatory fields, the form won't submit until I press the OK button on the alert box.
In Selenium, We Use the Following Methods To Handle Alerts:
- Void dismiss(): It is used to click on the ‘Cancel’ button of the alert box.
driver.switchTo().alert().dismiss();
- Void accept(): It is used to click on the ‘OK’ button of the alert.
driver.switchTo().alert().accept();
- String getText(): It is used to capture the alert message.
driver.switchTo().alert().getText();
- Void sendKeys(String stringToSend): It is used to send data to the alert box.
driver.switchTo().alert().sendKeys("Text");
Post a Comment