0

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

Andrea
  • 41
  • 2
  • 6
  • Try to increase the wait time. – Guy Jul 03 '17 at 07:47
  • By how much? I tried changing the wait time to 7 but it still outputs the same – Andrea Jul 03 '17 at 07:57
  • how about setting to higher value, like 30 seconds or more just to check it's not the timeout issue, also can you paste the screenshot of the alert just to make sure it's alert – Gaurang Shah Jul 03 '17 at 08:03
  • I already added the link to the screenshot of the alert. I'm not quite sure myself if it's really an alert or just a popup window. I also tried making the wait time 30 but the output is the same – Andrea Jul 03 '17 at 08:14
  • 1
    which browser are you using, it doesn't look like normal alert. Check this alert should look like this. https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_alert are you sure it's alert ? – Gaurang Shah Jul 03 '17 at 09:04
  • I'm using Firefox. I think it's just a pop-up window. – Andrea Jul 04 '17 at 00:37

0 Answers0