我正在使用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