Tuesday, October 18, 2011

Handling Javascript Popups Using Selenium-WebDriver

We can use the below methods to handle Javascript popups.

# accept()
This method can be used to click 'OK' button in a popup

WebDriver firefoxDriver=new FirefoxDriver();
Alert alert = firefoxDriver.switchTo().alert();//Creating object for Alert class
alert.accept();//Clicking OK button

# dismiss()
Canceling popup using dismiss method

WebDriver firefoxDriver=new FirefoxDriver();
Alert alert = firefoxDriver.switchTo().alert();
alert.dismiss();//Canceling the popup

# getText()
Getting popup text

String strAlertText;
WebDriver firefoxDriver=new FirefoxDriver();
Alert alert = firefoxDriver.switchTo().alert();
strAlertText=alert.getText();//This line retrieves text from popup.
System.out.println(strAlertText);

1 comment:

  1. Rerarding for query

    Features of TestNG and list some of the functionality in TestNG which makes it more effective?

    http://www.bestqtptraining.com/

    ReplyDelete