Filtering and performing actions on WebElements

Let's further modify the search test and find a product matching with a given name. We will then click on the product to open the product details page, as shown in this code:

@Test public void searchAndViewProduct() {     // find search box and enter search string     WebElement searchBox = driver.findElement(By.name("q"));     searchBox.sendKeys("Phones");     WebElement searchButton =             driver.findElement(By.className("search-button"));     searchButton.click();     assertThat(driver.getTitle())             .isEqualTo("Search results for: 'Phones'");     List<WebElement> searchItems = driver             .findElements(By.cssSelector("h2.product-name a"));     WebElement product = searchItems.stream() .filter(item -> item.getText().equalsIgnoreCase( ...

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.