The syntax of the until()
method in selenium docs is as below:
public <V> V until(java.util.function.Function<? super T,V> isTrue)
The usage of the same is like:
WebDriver wait = new WebDriver(driver, 20);
WebElement loginButton = wait.until(ExpectedConditions.elementToBeClickable(By.id("lgn-btn")));
I couldn't relate to the syntax and the usage of the until()
method. I want to know how the syntax is implemented.
Yeah, I know about Generics, which we use to know about the errors at compile time so that we can avoid ClassCastException at runtime. Also, I know about the functional interface, which we use to achieve behavior parameterization.
What I didn't get is the equivalence between the java.util.function.Function<? super T,V> isTrue)
and the ExpectedConditions.elementToBeClickable(By.id("id))
.
What does the expression java.util.function.Function<? super T,V> isTrue
mean?
There are four different topics mentioned within your question and you can find the details below:
java.util.function
The java.util.function package includes the Functional interfaces which provide the target types for lambda expressions and method references.
A few examples are:
BiConsumer<T,U>
: Represents an operation that accepts two input arguments and returns no result.BiFunction<T,U,R>
: Represents a function that accepts two arguments and produces a result.BinaryOperator<T>
: Represents an operation upon two operands of the same type, producing a result of the same type as the operands.BiPredicate<T,U>
: Represents a predicate (boolean-valued function) of two arguments.Consumer<T>
: Represents an operation that accepts a single input argument and returns no result.Function<T,R>
: Represents a function that accepts one argument and produces a result.Class FluentWait
The
public class FluentWait<T>
class extendsjava.lang.Object
and implementsWait<T>
which implies it is an implementation of the Wait interface that may have its timeout and polling interval configured on the fly. Each FluentWait instance defines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition. Furthermore, the user may configure the wait to ignore specific types of exceptions whilst waiting, such as NoSuchElementExceptions when searching for an element on the page.One of the modifier is:
This implementation repeatedly applies this instance's input value to the given function until one of the following occurs:
Interface ExpectedCondition
The
public interface ExpectedCondition<T>
interface extendscom.google.common.base.Function<WebDriver,T>
which models a condition that is expected to evaluate to something that is neither null nor false. Examples would include determining if a web page has loaded or that an element is visible.Class ExpectedConditions
The ExpectedConditions Class is the canned ExpectedConditions which are generally useful within webdriver tests.
A few usage examples:
elementToBeClickable()
:visibilityOfElementLocated()
:frameToBeAvailableAndSwitchToIt()
:visibilityOfAllElementsLocatedBy()
:attributeContains()
: