【问题标题】:Why is my code not working properly?为什么我的代码不能正常工作?
【发布时间】:2016-08-30 12:04:11
【问题描述】:

这是我的代码:

try {
     WebDriverWait wait = new WebDriverWait(driver, 10);
     Alert alert = wait.until(ExpectedConditions.alertIsPresent());

      //Accepting alert.
      alert.accept();
      System.out.println("Accepted the alert successfully.");
   } catch(Throwable e) {
      System.err.println("Error came while waiting for the alert popup. "+e.getMessage());
   }

错误显示如下:

等待弹出警报时出现错误。预期条件失败:等待警报出现(以 500 MILLISECONDS 间隔尝试 10 秒)

【问题讨论】:

  • 需要检查您的页面是否是 javascript 警报???
  • 先生,感谢您的回复。它是一个 javascript 警报消息,它是一个基于窗口的我认为 autoit 工具对此很有用.. 你的意见是什么?马上告诉我?等待回复..

标签: java selenium testing


【解决方案1】:

我建议使用以下代码。

WebDriverWait wait = new WebDriverWait(driver, 2);
wait.until(ExpectedConditions.alertIsPresent());
try{
    Alert alert = driver.switchTo().alert().accept();
}
catch (Exception e)
    System.out.println("No alert");

【讨论】:

    【解决方案2】:

    通常不需要等待警报。您可以使用普通代码,如

      Alert alert = webDriver.switchTo().alert();
    

    试试这个。 PS:这个 Alert 类只能通过 javascript 处理警报框,请检查您的警报是否不是由任何 html 元素组成的

    【讨论】:

    • 感谢您的休息。您对 autoit 工具有何看法?
    猜你喜欢
    • 1970-01-01
    • 2019-06-10
    • 1970-01-01
    • 2016-10-03
    • 1970-01-01
    • 2012-06-10
    • 2013-10-14
    • 2020-11-17
    • 2018-02-11
    相关资源
    最近更新 更多