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();

No comments:

Post a Comment