Pages

Thursday 8 March 2012

How can I handle alert dialog box?

Below method will handle the alert dialog displayed and also it will return the alert message displayed.

public String getAlert() { 
     Alert alert = driver.switchTo().alert(); 
     String alertMsg = alert.getText();
     alert.accept();
     return alertMsg; } 

3 comments:

  1. please say the coding for isAlertPresent() in selenium web driver ..how to check whether the alert is present or not...kindly say soon ...tom i need to submit my project...

    ReplyDelete
  2. For isAlertPresent() how to return boolean value in java ..say tat coding also

    ReplyDelete
  3. Check the below link:
    http://seleniumwebdriverfaq.blogspot.in/2012/05/how-to-check-presence-of-alert.html

    ReplyDelete