Java Code Examples for org.openqa.selenium.By#findElement()

The following examples show how to use org.openqa.selenium.By#findElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrowserTest.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
protected boolean clickSelectOption(WebElement element, String optionValue) {
    boolean result = false;
    if (element != null) {
        if (isSelect(element)) {
            optionValue = cleanupValue(optionValue);
            By optionBy = new OptionBy(optionValue);
            WebElement option = optionBy.findElement(element);
            result = clickSelectOption(element, option);
        }
    }
    return result;
}
 
Example 2
Source File: SingleElementOrNullBy.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
/**
 * Converts By to Function returning first result (or null).
 * @param by by to convert.
 * @return function returning first result of by.
 */
public static <T extends WebElement> Function<SearchContext, T> byToFunction(By by) {
    Function<SearchContext, T> function;
    if (by instanceof SingleElementOrNullBy) {
        // will not throw exception, but return null when no element is found
        function = sc -> (T) by.findElement(sc);
    } else {
        function = sc -> {
            // single element case will throw exception when no element is found
            List elements = by.findElements(sc);
            return (elements != null && !elements.isEmpty())? (T) elements.get(0) : null;
        };
    }
    return function;
}
 
Example 3
Source File: FirstElementBy.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
public static <T extends WebElement> T getWebElement(By by, SearchContext context) {
    T byResult;
    if (by instanceof SingleElementOrNullBy) {
        byResult = (T) by.findElement(context);
    } else {
        byResult = BestMatchBy.findElement(by, context);
    }
    return byResult;
}
 
Example 4
Source File: RemoteWebDriver.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public WebElement findElement(By locator) {
  if (locator instanceof By.StandardLocator) {
    return ((By.StandardLocator) locator).findElement(this, this::findElement);
  } else {
    return locator.findElement(this);
  }
}
 
Example 5
Source File: RemoteWebElement.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public WebElement findElement(By by) {
  if (by instanceof By.StandardLocator) {
    return ((By.StandardLocator) by).findElement(this, this::findElement);
  } else {
    return by.findElement(this);
  }
}