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

The following examples show how to use org.openqa.selenium.By#findElements() . 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: ByCollection.java    From xframium-java with GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<WebElement> findElements( SearchContext context )
{
    List<WebElement> elems = new ArrayList<>();
    for ( By by : bys )
    {
        List<WebElement> elementList = by.findElements( context );
        resultList.addAll( ( (ReportableBy) by ).getResults() );
        if ( elementList != null && !elementList.isEmpty())
        {
            elems.addAll( by.findElements( context ) );
            return elems;
        }
    }

    return elems;
}
 
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: RemoteWebDriver.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public List<WebElement> findElements(By locator) {
  if (locator instanceof By.StandardLocator) {
    return ((By.StandardLocator) locator).findElements(this, this::findElements);
  } else {
    return locator.findElements(this);
  }
}
 
Example 4
Source File: RemoteWebElement.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public List<WebElement> findElements(By locator) {
  if (locator instanceof By.StandardLocator) {
    return ((By.StandardLocator) locator).findElements(this, this::findElements);
  } else {
    return locator.findElements(this);
  }
}
 
Example 5
Source File: Element.java    From JTAF-ExtWebDriver with Apache License 2.0 5 votes vote down vote up
@Override
public List<WebElement> findElements(SearchContext context) {
    for (By by : bys) {
        try {
            final List<WebElement> element = by.findElements(context);
            if (element != null && element.size() > 0) {
                return element;
            }
        } catch (Exception e) {
            // ignored
        }
    }
    return null;
}