wait.until(ExpectedConditions) 在硒中不再起作用 [英] wait.until(ExpectedConditions) doesnt work any more in selenium

查看:30
本文介绍了wait.until(ExpectedConditions) 在硒中不再起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我使用的是 2.45.0 版本的 selenium,我所有的等待都是这样完成的:

So far I used 2.45.0 version of selenium and all my waits were done in this way:

WebDriverWait wait = new WebDriverWait(webKitUtility.getWebDriver(), 5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("role")));

但是我将 selenium 更新到 3.1.0 并且出现错误:

But I updated selenium to 3.1.0 and I am getting the error:

"FluentWait 类型中的方法until(Predicate)不适用于参数(预期条件)"

"The method until(Predicate) in the type FluentWait is not applicable for the arguments (ExpectedCondition)"

我看到从 2.45.0 到 3.1.0 有些东西被弃用了.我正在尝试调查现在最好的方法是什么,但我不确定.我在谷歌上找到的大部分内容都是旧信息,解释了我目前使用的相同方式.

I see that from 2.45.0 to 3.1.0 some things are deprecated. I am trying to investigate what is the best way to do it now, but I am not sure. Most of the things I'm finding on google are old information explaining the same way I was using so far.

推荐答案

我遇到了同样的问题.

我通过使用 WebDriverWait 的未弃用的 .until() 方法并将以下内容添加到我的 maven pom.xml 中来修复它:

I fixed it by using the not deprecated .until() method of WebDriverWait and by adding the following to my maven pom.xml:

<dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>21.0</version>
</dependency>

除此之外,我的代码看起来和以前一模一样.

Other than that, my code looks exactly like before.

更具体地说,现在有两个 .until() 方法.

To be more specific there are now two .until() methods.

旧的(已弃用):
public void until(final Predicate isTrue) {}

还有新的:
public <V>V until(Function isTrue) {}

这篇关于wait.until(ExpectedConditions) 在硒中不再起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆