/** * Compiles the selector for the given context (the context will determinate what selectors are natively * supported and what selectors should be handled by SeleniumQuery programatically) and matches elements based on it. */ @Override public List<WebElement> findElements(SearchContext context, String selector) { TagComponentList xPathLocator = XPathComponentCompilerService.compileSelectorList(selector); return xPathLocator.findWebElements(context); }
/** * Compiles the selector for the given context (the context will determinate what selectors are natively * supported and what selectors should be handled by SeleniumQuery programatically) and matches elements based on it. */ @Override public List<WebElement> findElements(SearchContext context, String selector) { TagComponentList xPathLocator = XPathComponentCompilerService.compileSelectorList(selector); return xPathLocator.findWebElements(context); }
@Override public boolean isPseudoClass(WebDriver driver, WebElement element, PseudoClassSelector pseudoClassSelector) { String hasSelector = pseudoClassSelector.getPseudoClassContent(); TagComponentList compiledSelector = XPathComponentCompilerService.compileSelectorList(hasSelector); List<WebElement> elements = compiledSelector.findWebElements(driver); return !elements.isEmpty(); }
@Override public boolean isPseudoClass(WebDriver driver, WebElement element, PseudoClassSelector pseudoClassSelector) { String hasSelector = pseudoClassSelector.getPseudoClassContent(); TagComponentList compiledSelector = XPathComponentCompilerService.compileSelectorList(hasSelector); List<WebElement> elements = compiledSelector.findWebElements(driver); return !elements.isEmpty(); }
@Test public void findWebElements_should_call_findElementsByXPath() { // given TagComponentList tagComponentList = XPathComponentCompilerService.compileSelectorList("span"); SearchContext searchContext = createSearchContextThatReturnsWebElementsForXPath("(.//*[self::span])", dummyWebElements); // when List<WebElement> webElements = tagComponentList.findWebElements(searchContext); // then assertThat(webElements, is(dummyWebElements)); }
@Test public void findWebElements_if_selector_is_just_an_id_it_should_call_findElementById() { // given TagComponentList tagComponentList = XPathComponentCompilerService.compileSelectorList("#idz"); SearchContext searchContext = createSearchContextThatReturnsWebElementForId("idz", firstDummyWebElement); // when List<WebElement> webElements = tagComponentList.findWebElements(searchContext); // then assertThat(webElements, contains(firstDummyWebElement)); }