【问题标题】:why wait.until doesn't work in selenium but thread.sleep does? [duplicate]为什么 wait.until 在 selenium 中不起作用但 thread.sleep 起作用? [复制]
【发布时间】:2019-04-01 09:50:57
【问题描述】:

用一段代码代替

Thread.sleep (4000);

我要使用

from wait.until (ExpectedConditions.visibilityOfElementLocated (By.xpath ("// div [@class = \" x-tool-img x-tool-expand-bottom x-rtl \ "]")));

我看到错误但使用 Thread.sleep 我没有错误消息并且代码很容易通过我不知道为什么不通过 wait.until ??

感谢您的指导

【问题讨论】:

  • 错误是什么?请发布真实代码,这不是有效的 Java 语法。

标签: java multithreading selenium


【解决方案1】:

尝试使用此有效格式。

WebDriverWait wait = new WebDriverWait(driver, 5);
WebElement e4 = wait.until(ExpectedConditions.visibilityOf(ElementtobeVisible));

或查看此Link,它会很有帮助。

【讨论】:

    【解决方案2】:

    wait 的有效语法可以在这里找到: https://www.seleniumhq.org/docs/04_webdriver_advanced.jsp

    WebDriverWait wait = new WebDriverWait(driver, 10);
    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
    

    【讨论】:

      猜你喜欢
      • 2014-08-15
      • 2018-10-27
      • 1970-01-01
      • 2018-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-26
      • 2013-08-13
      相关资源
      最近更新 更多