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