Chapter 3

  1. Which version of Java Streams API is introduced?

Java 8.

  1. Explain the filter function of Streams API.

Java Stream API provides a filter() method to filter stream elements on the basis of the given predicate. Suppose we want to get all the link elements that are visible on the page, we can use the filter() method to return the list in the following way:

List<WebElement> visibleLinks = links.stream()   .filter(item -> item.isDisplayed())    .collect(Collectors.toList());
  1. Which method of Streams API will return the number of matching elements from the filter() function?

count().

  1. We can use the map() function to filter a list of WebElements by attribute values: True or false?

False.

Get Selenium WebDriver 3 Practical Guide - Second Edition 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.