My program will click a Search button and detect if a popup alert shows. If an alert shows, it must click "ok" or else it will just proceed with the rest of the program. This is my code for handling the alert. Unfortunately, after clicking the Search button, the program outputs "There is no alert". I don't know why the code can't detect the alert.
public static void checkAlert() {
try {
WebDriverWait wait = new WebDriverWait(driver, 2);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.accept();
} catch (Exception e) {
System.out.println("There is no alert");
}
}
This is the link to the screenshot of the popup alert
UPDATE: I was able to solve my problem. The solution that worked for me is found here: How to handle Pop-up in Selenium WebDriver using Java