【发布时间】:2017-07-05 15:57:44
【问题描述】:
我正在与Selenium Standalone Server 3.0.1 合作。我正在尝试将Explicit Wait 添加到我的代码中,以在元素变得可见时通过xpath 检测元素。为了获得一些 Java 帮助,我查找了 Selenium Standalone Server 3.0.1 的源代码,但找不到它。我在selenium-java-2.53.1 版本中找到了源代码。我下载它并找到selenium-java-2.53.1-srcs 并添加到我的Eclipse IDE。在FluentWait 的帮助下,我简单地将代码复制粘贴到我的Eclipse IDE 中并更改了变量名。
文档中的示例代码如下:
// Waiting 30 seconds for an element to be present on the page, checking
// for its presence once every 5 seconds.
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("foo"));
}
});
但是当我实现这段代码时,只需复制粘贴即可:
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(5, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
WebElement element = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.xpath("//p[text()='WebDriver']"));
}
});
我在 FluentWait Class as The type FluentWait is not generic; it cannot be parameterized with arguments <WebDriver> 上遇到错误
这是我的进口清单:
import java.util.concurrent.TimeUnit;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Wait;
import com.google.common.base.Function;
谁能帮帮我?
更新
在 Selenium v3.11.0
中针对 FluentWait 的修改构造函数添加了 answer【问题讨论】:
-
@JeffC 谢谢。我可以看到 selenium-java-2.53.1 src 代码提供的文档与您共享的 URL 中提供的文档之间存在一些差异。在 selenium-java-2.53.1 src 代码中,创建对象是 wait = new FluentWait
(driver) -->> 但链接文档说它是 >
标签: java selenium selenium-webdriver webdriver fluentwait