I need to check the existence of Alert in WebDriver.
Sometimes it pops up an alert but sometimes it will not pop up. I need to check if the alert exists first, then
public static void handleAlert(){ if(isAlertPresent()){ Alert alert = driver.switchTo().alert(); System.out.println(alert.getText()); alert.accept(); } } public static boolean isAlertPresent(){ try{ driver.switchTo().alert(); return true; }catch(NoAlertPresentException ex){ return false; } }