我正在使用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
中的代码并更改了变量名称。Selenium Webdriver 3.0.1- [Eclipse-Java-Chrome]:Selenium显示FluentWait类错误
在文档中的示例代码是这样的:
// 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
类得到一个错误,因为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;
任何人都可以帮助我吗?
@blalasaadri @Mira从你的最后有什么建议吗?
你尝试了文档的例子吗? https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/FluentWait.html – JeffC
@JeffC谢谢。我可以看到selenium-java-2.53.1 src代码提供的文档与您共享的URL中提供的文档有一些区别。在selenium-java-2.53.1 src代码中,创建一个对象是<< - 等待 wait = new FluentWait (驱动程序) - >>但链接文档将其描述为<< - Wait wait = new FluentWait (driver) - >> –
DebanjanB