public ElementNotFound(Driver driver, By searchCriteria, Condition expectedCondition) { this(driver, searchCriteria.toString(), expectedCondition, null); }
public static String selector(By selector) { return selector.toString() .replaceFirst("By\\.selector:\\s*", "") .replaceFirst("By\\.cssSelector:\\s*", ""); } }
public WebElement findElement(SearchContext searchContext) { List<WebElement> elements = searchContext.findElements(by); if (next != null) { if (index > 0 ) { if (index <= elements.size()) { return next.findElement(elements.get(index - 1)); } } else { if (elements.size() > 0) { return next.findElement(elements.get(0)); } } } else { if (index > 0) { if (index <= elements.size()) { return elements.get(index - 1); } } else { if (elements.size() > 0) { return elements.get(0); } } } throw new NoSuchElementException(by.toString() + " | index " + index); }
@Override public String toString() { return map.get(currentContent).toString(); } }
@Override public String toString() { return by.toString(); } }
@Override public void afterFindBy(By by, WebElement element, WebDriver driver) { messages.add("WebDriverEventListener: The searching for something using " + by.toString() + " has beed finished. " + "The root element was " + String.valueOf(element)); }
@Override public void beforeFindBy(By by, WebElement element, WebDriver driver) { messages.add("Externally defined listener: Attempt to find something using " + by.toString() + ". The root element is " + String.valueOf(element)); }
@Override public void afterFindBy(By by, WebElement element, WebDriver driver) { messages.add("Externally defined listener: The searching for something using " + by.toString() + " has beed finished. " + "The root element was " + String.valueOf(element)); }
@Override public void beforeFindBy(By by, WebElement element, WebDriver driver) { messages.add("WebDriverEventListener: Attempt to find something using " + by.toString() + ". The root element is " + String.valueOf(element)); }
@Override public void afterFindBy(By by, WebElement element, WebDriver driver) { messages.add("The searching for something using " + by.toString() + " has beed finished. " + "The root element was " + String.valueOf(element)); }
@Override public void beforeFindBy(By by, WebElement element, WebDriver driver) { messages.add("Attempt to find something using " + by.toString() + ". The root element is " + String.valueOf(element)); }
protected static void checkThatLocatorsAreCreatedCorrectly(DefaultStubWidget single, List<DefaultStubWidget> multiple, By rootLocator, By subLocator) { assertThat(single.toString(), containsString(rootLocator.toString())); assertThat(multiple.stream().map(DefaultStubWidget::toString).collect(toList()), contains(containsString(rootLocator.toString()), containsString(rootLocator.toString()))); assertThat(single.getSubWidget().toString(), containsString(subLocator.toString())); assertThat(single.getSubWidgets().stream().map(Object::toString).collect(toList()), contains(containsString(subLocator.toString()), containsString(subLocator.toString()))); assertThat(multiple.stream().map(abstractWidget -> abstractWidget.getSubWidget().toString()).collect(toList()), contains(containsString(subLocator.toString()), containsString(subLocator.toString()))); } }
/** * Find the element. */ public WebElement findElement() { if (cachedElement != null && shouldCache) { return cachedElement; } By bySearching = getBy(this.by, searchContext); try { WebElement result = waitFor(() -> searchContext.findElement(bySearching)); if (shouldCache) { cachedElement = result; } return result; } catch (TimeoutException | StaleElementReferenceException e) { throw new NoSuchElementException(format(exceptionMessageIfElementNotFound, bySearching.toString()), e); } }
/** * Find Extended Web Element on page using By starting search from this * object. * * @param by Selenium By locator * @param timeout to wait * @return ExtendedWebElement if exists otherwise null. */ public ExtendedWebElement findExtendedWebElement(By by, long timeout) { return findExtendedWebElement(by, by.toString(), timeout); }
/** * Find Extended Web Element on page using By. * * @param by * Selenium By locator * @return ExtendedWebElement if exists otherwise null. */ public ExtendedWebElement findExtendedWebElement(By by) { return findExtendedWebElement(by, by.toString(), EXPLICIT_TIMEOUT); }
/** * Find Extended Web Element on page using By. * * @param by * Selenium By locator * @param timeout to wait * @return ExtendedWebElement if exists otherwise null. */ public ExtendedWebElement findExtendedWebElement(By by, long timeout) { return findExtendedWebElement(by, by.toString(), timeout); }
/** * Find Extended Web Element on page using By starting search from this * object. * * @param by Selenium By locator * @return ExtendedWebElement if exists otherwise null. */ public ExtendedWebElement findExtendedWebElement(By by) { return findExtendedWebElement(by, by.toString(), EXPLICIT_TIMEOUT); }
@Override public String toString() { SmartAnnotations annotations = new SmartAnnotations(field, platform); By by = annotations.buildBy(); return by.toString(); } }
private WebElement findElement(long timeout) { if (element != null) { return element; } if (isPresent(timeout)) { //TODO: investigate maybe searchContext better to use here! element = getDriver().findElement(by); } else { throw new NoSuchElementException("Unable to detect element using By: " + by.toString()); } return element; }