Firefox alert box not detected with Selenium WebDriver

后端 未结 2 1545
一生所求
一生所求 2021-01-28 14:07

ERROR net.serenitybdd.core.Serenity - No alert is present (WARNING: The server did not provide any stacktrace information)

I get this erro

相关标签:
2条回答
  • 2021-01-28 14:10

    You might need to add code to wait for the alert to be visible. Selenium can't tell if JavaScript has finished executing.

    waitForAlert(WebDriver driver)
    {
       int i=0;
       while(i++<5)
       {
            try
            {
                Alert alert = driver.switchTo().alert();
                break;
            }
            catch(NoAlertPresentException e)
            {
              Thread.sleep(1000);
              continue;
            }
       }
    }
    
    0 讨论(0)
  • 2021-01-28 14:18

    A little more elegant solution :

    WebDriverWait wait = new WebDriverWait(driver, timeout);
    wait.until(ExpectedConditions.alertIsPresent());
    

    Use the WebDriverWait, every time you have dynamic element that are not present when the page is done loading, like alert, popupwindow, modal popup, hiden element which turn visible,.

    0 讨论(0)
提交回复
热议问题