InBrowserFinder { static WebElement find(WebDriver driver, final Path el) { final Optional<String> path = el.getXPath(); try { if (el.getUnderlyingSource().isPresent()) { WebElement underlying = el.getUnderlyingSource().get(); return (path.isPresent()) ? underlying.findElement(By.xpath(path.get())) : underlying; } else { if (el.getXPath().isPresent()) { String processedPath = processedPathForFind(path.get()); return driver.findElement(By.xpath(processedPath)); } else { throw new IllegalArgumentException("path is empty"); } } } catch (org.openqa.selenium.NoSuchElementException ex) { throw new NoSuchElementException("could not find " + el, ex); } }  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 findWithUnderlying() { when(webElement.findElement(By.xpath(BasicPath.div.getXPath().get()))).thenReturn(webElement2); Path path = BasicPath.builder().withUnderlying(webElement).withXpath("div").build(); assertThat(InBrowserFinder.find(driverMock, path), is(webElement2)); }