The until()
method in org.openqa.selenium.support.ui.FluentWait
is overloaded for Predicate<T>
and Function<? super T, V>
interfaces as parameters.
It should take as argument one of the following (which implement the apply()
method):
- Anonymous class
- Lambda expression
- Method reference
Any lambda that I define as argument for this method throws following error:
The method until(Predicate) is ambiguous for the type WebDriverWait
My Lambda:
x -> x.findElement(byLocator).isDisplayed()
I assume this will be the case for any lambda, as apply()
for either Function or Predicate can be implemented by use of these lambda.
So my question is what is the use of the until method which takes Predicate as parameter?
Updated: Removed the first part of question which was answered by @drkthng.
Below functional interface implementation should resolved issue:
Answering your first question:
Have a look at the Selenium API docs for ExpectedConditon.
I quote:
You see, that ExpectedCondition inherited from google's Function interface, thus you can use it as an argument for the until() method.
As for your second question:
I don't think you can hand over a lambda just like that. Until method is waiting for a Predicate or Function (as you correctly mentioned).
Regarding the differences between Predicates and lambdas, have a look for example here
So you can try something like this instead, still using your lambda-expressions:
As you said the method
until
is overloaded and the parameters expected arePredicate<T>
andFunction<? super T, V>
.Your lambda expression match both signatures, so the call to the method is ambiguous, to solve the ambiguity, there are several options:
Cast the lambda expression to the desired type:
If you create a variable for the lambda expression, the cast is not needed:
If you have a method with this functionality, you can use a method reference:
You are getting the error as your lambda expression match both the predicate and function.
Consider upgrading the selenium to v3.2.0 -> in which the
FluentWait.until(Predicate<?>)
method is deprecated. And that should make lambdas work properly with Wait instances now.