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

相关文章:

  • 2021-11-14
  • 2021-11-14
  • 2021-04-19
  • 2021-05-29
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
  • 2021-08-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-24
  • 2022-12-23
  • 2021-06-10
  • 2022-12-23
  • 2021-11-14
相关资源
相似解决方案