It is very simple to handle javascript alerts in WebDriver. If we don't handle the alerts properly WebDriver will throw UnhandledAlertException .
Handling javascript alerts
In web application mostly we see two types of pop-ups, 1. alerts 2. confirm popup
I hope this would help you to handle javascript alerts.
Happy coding :)
Regards,
SantoshSarma
In web application mostly we see two types of pop-ups, 1. alerts 2. confirm popup
Handling both alerts & confirms popup WebDriver has a Alert interface. Using WebDriver you can click on OK or Cancel button and also can get alert message also to verify.
Logic
//First we need switch the control to alert.
Alert alert = driver.switchTo().alert();
//Getting alert text
alert.getText();
//Click on OK
alert.accept();
//Click ok Cancel
alert.dismiss();
I hope this would help you to handle javascript alerts.
Happy coding :)
Regards,
SantoshSarma
Related topics
Executing Java script using selenium
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.