Thursday, August 9, 2012

Handling alerts in Selenium webdriver


Handling alerts in Webdriver :

Import this package in your script.
#import org.openqa.selenium.Alert;

For accepting the alert box:
Alert al = driver.switchTo ().alert ();
al.accept ();
       
For cancelling the alert box:
Alert al = driver.switchTo ().alert ();
al.dismiss ();

For getting the text of the alert box:

Alert al = driver.switchTo ().alert ();
String s = al.getText();
System.out.println(s);

4 comments:

  1. How to handle Authentication alert boxes?? Can you explain?

    Thanks

    ReplyDelete
  2. Hi Tester,

    Did you mean, SSL alert/Security alert? Or

    Username, Password authentication??

    Thanks
    Anitha

    ReplyDelete
  3. Using AutoIT, we can handle this type of alerts. We will share the AutoIT scripts very shortly.

    ReplyDelete