Showing posts with label javascript alerts with web driver. Show all posts
Showing posts with label javascript alerts with web driver. Show all posts

How to handle Javascript alerts and prompts with WebDriver?

Use Alert API for this:
 
 
 Get a handle to the open alert, prompt:
Alert alert = driver.switchTo().alert();
// Get the text of the alert or prompt
alert.getText(); 
 // And acknowledge the alert or click "OK"
alert.accept();
 
//Reject the alert or click "NO" 
alert.reject();