How to close the dialog box using Selenium WebDriver

03 April, 2014
On some websites when you click on an object a dialog will pop up asking your conformation. To close this kind of alert messages, we can use the below code.

import org.openqa.selenium.Alert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class PopupDialog 
{
 public static void main(String[] args) 
 {
  WebDriver driver=new FirefoxDriver();
  driver.get("http://www.agoda.com/?ymsg=1&tick=634955861691");
 
  Alert alt=driver.switchTo().alert();
  alt.accept();
 }
}

No comments:

Post a Comment