Functions

We are going to create a very basic function that will find and return WebElement. Take a look at this code:

Function<WebDriver, WebElement> weFindElementFoo = new Function<WebDriver, WebElement>() {     public WebElement apply(WebDriver driver) {         return driver.findElement(By.id("foo"));     } };

The function may look confusing, but it is actually quite simple. It is simply specifying an input and an output. Let's break it down and take the object definition in isolation. Look at this code:

Function<WebDriver, WebElement> weFindElementFoo 

What we are saying is that we are going to create a function named weFindElementFoo(). We are going to supply this function with an object of type WebDriver as the input, and we will get an object of ...

Get Mastering Selenium WebDriver 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.