Selenium WebDriver and Java 8


From Selenium 3.0, minimum Java version is 8. In this blog article, we would like to show you how to use Java 8 features like Lambda expression and Collections Stream to simplify Selenium webdriver snippets.
Let’s start with Lambda expression.
Java lambda expressions are Java’s first step into functional programming. A Java lambda expression is thus a function which can be created without belonging to any class. A lambda expression can be passed around as if it was an object and executed on demand.
Source: Tutorials Jenkov Let’s say you want to print all the elements from an array list without lambda expression; then you will come up with the below snippet.
The same logic, we can implement a lot easier with lambda expression in Java 8.
Collections Stream
Collections Stream is a new feature in Java 8. A stream represents a sequence of elements and supports different kind of operations from a collection. Let’s say you want to check whether an option is available or not in a drop-down list.
Filtering WebElements using Regular Expression
Very Simple, isn’t it?

Leave a Reply

Your email address will not be published. Required fields are marked *