O'Reilly logo

Mastering Selenium WebDriver 3.0 by Mark Collin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required