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