Function keyword

In the preceding example, we have used Function keyword in the form of new Function<WebDriver, WebElement>().

When we use Function, we can return any value. In this case, we return a web element. All instances of Function should have a single method called apply, which in the preceding case takes a WebDriver object as a parameter and returns the WebElement that is obtained from the findElement method. The advantage of using instances of Function is that one can pass an object of any type as the input and return an object of any type as the output.

It is not just web elements that can be returned. We can even return a Boolean condition. Boolean conditions of the kind shown in the following code are allowed:

return driver.findElements(By.id("xyz")).size() > 0 

The apply method will look like the one shown in the following code when they are used to return a Boolean value:

new Function<WebDriver, Boolean>() {
public Boolean apply(WebDriver driver) {
//Processing comes here
}
};

Let's have a look at some web pages that are created using JQuery and AJAX. In the following section, we will create a page using the JQuery library.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.121.170