Why can't I find the 'Function' function in webDriver?
I want to implement a simple waitForXX under webdriver.
The code is pretty simple.
Function<WebDriver, WebElement> presenceOfElementLocated(final By locator) {
return new Function<WebDriver,开发者_开发技巧 WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(locator);
}
};
}
But still it gives me troubles because I can't seem to import the 'Function' part.
I looked every where under selenium.support.ui where it is supposed to be I guess? But I can't seem to locate it.
I tried with the latest Selenium standalone jar file 2.5.0.
Thanks!
Function<F, t>
seems to be from the Guava library. Do you have the Guava jars?
Unfortunately I don't know how to do that in Java but have you had a look at the WebDriverWait class in WebDriver which should do what you want.
The class is in the Support part of the Java Bindings
http://code.google.com/p/selenium/source/browse/trunk/java/client/src/org/openqa/selenium/support/ui/WebDriverWait.java
See how to use it with these tests
http://code.google.com/p/selenium/source/browse/trunk/java/client/test/org/openqa/selenium/support/ui/WebDriverWaitTest.java
Or you could use implicit waits
driver.manage().timeouts().implicitlyWait(3000, MILLISECONDS);
driver.findElement(By.id('foo')); //will wait 3 seconds, if not loaded will throw an exception
精彩评论