InBrowserFinder { public static List<WebElement> findAll(WebDriver driver, final Path el) { final Optional<String> path = el.getXPath(); if (el.getUnderlyingSource().isPresent()) { WebElement underlying = el.getUnderlyingSource().get(); if (path.isPresent()) { return underlying.findElements(By.xpath(path.get())); } else { return Collections.singletonList(underlying); } } else { if (path.isPresent()) { String processedPath = processedPathForFind(path.get()); return driver.findElements(By.xpath(processedPath)); } else { throw new IllegalArgumentException("webel is empty"); } } }  static List<WebElement> findAll(WebDriver driver, final Path el); static WebElement findPageWithNumberOfOccurrences(WebDriver driver, final Path el, int numberOfOccurrences); static WebElement findPageWithNumberOfOccurrences(WebDriver driver, final Path el, int numberOfOccurrences, RelationOperator relationOperator);  }
@Test public void findAllUnderlying() { List<WebElement> expected = Collections.singletonList(webElement2); when(webElement.findElements(By.xpath(BasicPath.div.getXPath().get()))).thenReturn(expected); Path path = BasicPath.builder().withUnderlying(webElement).withXpath("div").build(); assertThat(InBrowserFinder.findAll(driverMock, path), is(equalTo(expected))); }