0

I'm automating this site as a practice https://www.demoblaze.com/index.html, after completing sign up modal and click Sign Up button, another pop up is raised to confirm the sign up process.

If I don't catch the alert modal I get "org.openqa.selenium.UnhandledAlertException: unexpected alert open: {Alert text : Sign up successful.}"

but if I handle the alert like this:

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
        try {
            driver.switchTo().alert().accept();
        }
        catch (NoAlertPresentException Ex) {
            System.out.println("no hay alerta");
        }

I get "org.openqa.selenium.NoAlertPresentException: no such alert" When I debugged the test, it skips the try/catch sentence.

I also see that I cannot inspect with Chrome browser dev tools or Xpath Helper.

Jillbarvi
  • 15
  • 1
  • 4
  • Try introducing a ` webdriverwait` instead of `implicitlywait`. Now, I am a python guy and I wrote the code in python and it worked for me. I used `Thread.sleep` of 3 seconds. If inducing `sleep` also does not work, then please show your full code to debug the issue. – Anand Gautam Aug 17 '22 at 05:21

1 Answers1

0

You should wait for the Alert using webDriver wait like below and then switch to it

new WebDriverWait(driver, Duration.ofSeconds(60)).ignoring(NoAlertPresentException.class)
            .until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    alert.accept();
Abhay Chaudhary
  • 1,763
  • 1
  • 8
  • 13
  • .ignoring(NoAlertPresentException.class) was the solution I tried and it worked just wonderful, thank you all for taking the time to help me on this. Really appreciate it – Jillbarvi Aug 23 '22 at 05:33