[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();
  }
}

上一篇:selenium+python自动化77-autoit文件上传


下一篇:selenium+python自动化77-autoit文件上传【转载】