[Selenium] close alert window

public static boolean isAlertPresent(WebDriver driver) {

  try {
  driver.switchTo().alert();
    return true;
  } catch (NoAlertPresentException ex) {
    return false;
  }
}

 

/**
* Sometimes will pop up an alert window, you can use this method to close
* it.
*/
public static void closeAlert(WebDriver driver, boolean acceptAlert) {
  Alert alert = driver.switchTo().alert();
  if (acceptAlert) {
    alert.accept();
  } else {
    alert.dismiss();
  }
}

posted @ 2015-06-04 10:11  *飞飞*  阅读(377)  评论(0编辑  收藏  举报