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):
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.
Answering your first question:
Have a look at the Selenium API docs for ExpectedConditon.
I quote:
public interface ExpectedCondition<T>
extends com.google.common.base.Function<WebDriver,T>
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:
Predicate<WebDriver> myPredicate = x ->x.findElement(By.id("id")).isDisplayed();
WebDriverWait wait = (WebDriverWait)new WebDriverWait(driver, 10);
wait.until(myPredicate);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With