wait.until(ExpectedConditions) doesnt work any more in selenium
Solution 1:
I had the same issue.
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.
To be more specific there are now two .until()
methods.
The old one (which is deprecated):public void until(final Predicate<T> isTrue) {}
And the new one:public <V> V until(Function<? super T, V> isTrue) {}
Solution 2:
Note if you are using Maven that order of the dependencies do matter.
For example:
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "/Users/me/geckodriver");
final WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com");
final WebDriverWait wait = new WebDriverWait(driver, 5);
final By feelLuckyXpath = By.xpath("//div[@class='jsb']/center/input[@type='submit' and @name='btnI']");
wait.until(ExpectedConditions.visibilityOfElementLocated(feelLuckyXpath)).click();
driver.close();
}
this code works fine with the following maven dependencies:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.22.0</version>
</dependency>
but it may fail with reordered one:
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.8.1</version>
</dependency>
In this case because the google-api-client
contains:
<groupId>com.google.guava</groupId>
<artifactId>guava-jdk5</artifactId>
as dependency which shadows the guava
lib in the selenium
lib.
In this case the error is:
no instance(s) of type variable(s) V exist so that ExpectedCondition<> ...
method until in class org.openqa.selenium.support.ui.FluentWait cannot be applied to given types; required: java.util.function.Function found: org.openqa.selenium.support.ui.ExpectedCondition reason: cannot infer type-variable(s) V (argument mismatch; org.openqa.selenium.support.ui.ExpectedCondition cannot be converted to java.util.function.Function)