Example usage for org.openqa.selenium SearchContext findElements

List of usage examples for org.openqa.selenium SearchContext findElements

Introduction

In this page you can find the example usage for org.openqa.selenium SearchContext findElements.

Prototype

List<WebElement> findElements(By by);

Source Link

Document

Find all elements within the current context using the given mechanism.

Usage

From source file:com.arcbees.test.ByDebugId.java

License:Apache License

@Override
public List<WebElement> findElements(SearchContext context) {
    return context.findElements(By.id(UIObject.DEBUG_ID_PREFIX + debugId));
}

From source file:com.epam.jdi.site.epam.CustomElements.TreeDropdown.java

License:Open Source License

@Override
protected void selectAction(String name) {
    expandAction();/*w  w  w .j av a2  s.  c  om*/
    String[] nodes = name.split(" > ");
    SearchContext context = getDriver();
    if (treeLocators.size() < nodes.length)
        return;
    for (int i = 0; i < nodes.length; i++) {
        String value = nodes[i];
        List<WebElement> els = context.findElements(correctXPaths(treeLocators.get(i)));
        if (els.size() == 0)
            throw exception(
                    "No elements found for locator: " + treeLocators.get(i) + "in TreeDropdown " + this);
        context = first(els, el -> el.getText().equals(value));
        if (context == null)
            throw exception("Can't find: " + value + "in TreeDropdown " + this);
        if (i < nodes.length - 1) {
            int next = i + 1;
            boolean nextValue = LinqUtils.any(context.findElements(correctXPaths(treeLocators.get(next))),
                    el -> el.getText().equals(nodes[next]));
            if (nextValue)
                continue;
        }
        ((WebElement) context).click();
    }
}

From source file:com.epam.jdi.uitests.mobile.appium.elements.apiInteract.GetElementModule.java

License:Open Source License

private List<WebElement> searchElements() {
    SearchContext searchContext = containsRoot(getLocator()) ? getDriver()
            : getSearchContext(element.getParent());
    By locator = containsRoot(getLocator()) ? trimRoot(getLocator()) : getLocator();
    if (frameLocator != null)
        getDriver().switchTo().frame((WebElement) getDriver().findElement(frameLocator));
    return searchContext.findElements(correctXPaths(locator));
}

From source file:com.epam.jdi.uitests.web.selenium.elements.apiInteract.GetElementModule.java

License:Open Source License

private List<WebElement> searchElements() {
    SearchContext searchContext = containsRoot(getLocator()) ? getDriver()
            : getSearchContext(element.getParent());
    By locator = containsRoot(getLocator()) ? trimRoot(getLocator()) : getLocator();
    if (frameLocator != null)
        getDriver().switchTo().frame(getDriver().findElement(frameLocator));
    return searchContext.findElements(correctXPaths(locator));
}

From source file:com.galenframework.page.selenium.ByChain.java

License:Apache License

public List<WebElement> findElements(SearchContext searchContext) {
    List<WebElement> elements = searchContext.findElements(by);

    if (next != null) {
        if (index > 0) {
            if (index <= elements.size()) {
                return next.findElements(elements.get(index - 1));
            } else {
                return Collections.emptyList();
            }//from  w  w  w .j  a  v a  2s . com

        } else {
            if (elements.size() > 0) {
                return next.findElements(elements.get(0));
            } else {
                return Collections.emptyList();
            }
        }
    } else {
        return elements;
    }
}

From source file:com.galenframework.page.selenium.ByChain.java

License:Apache License

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));
            }/* www . j a v a  2 s .  c  o m*/
        } 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);
}

From source file:com.ggasoftware.jdiuitest.web.selenium.elements.apiInteract.GetElementModule.java

License:Open Source License

private List<WebElement> searchElements() {
    if (this.context == null || this.context.isEmpty())
        return getDriver().findElements(byLocator);
    SearchContext context = (rootElement != null) ? rootElement : getSearchContext(correctXPaths(this.context));
    return context.findElements(correctXPaths(byLocator));
}

From source file:com.github.wiselenium.Wiselenium.java

License:Open Source License

/**
 * Finds all elements within the search context using the given mechanism. <br/>
 * An empty list will be returned if the elements couldn't be found. <br/>
 * //from w w  w  . j a  v a2s .c o  m
 * @param clazz The class of the elements.
 * @param by The locating mechanism to use.
 * @param searchContext The search context.
 * @return The list of elements.
 * @since 0.3.0
 */
public static <E> List<E> findElements(Class<E> clazz, By by, SearchContext searchContext) {
    List<WebElement> webElements = searchContext.findElements(by);
    if (webElements.isEmpty())
        return Lists.newArrayList();

    WiseDecorator decorator = new WiseDecorator(new DefaultElementLocatorFactory(searchContext));
    return decorator.decorate(clazz, webElements);
}

From source file:com.mengge.pagefactory.bys.ContentMappedBy.java

License:Apache License

@Override
public List<WebElement> findElements(SearchContext context) {
    return context.findElements(map.get(WebDriverUnpackUtility.getCurrentContentType(context)));
}

From source file:com.qwazr.crawler.web.driver.BrowserDriver.java

License:Apache License

public String getSnippet(SearchContext searchContext, int sizeLimit) {
    List<WebElement> elements = searchContext.findElements(By.tagName("p"));
    if (elements == null)
        return null;
    StringBuilder sb = new StringBuilder();
    for (WebElement element : elements) {
        String text = null;/*from   w  w w .j a  v  a  2 s  .  c  o  m*/
        try {
            text = getTextSafe(element);
        } catch (CSSException e) {
            if (logger.isWarnEnabled())
                logger.warn("Cannot extract snippet: " + e.getMessage(), e);
        }
        if (text == null)
            continue;
        text = StringUtils.join(StringUtils.split(text, " \r\n\t"), ' ');
        sb.append(text);
        if (!text.endsWith("."))
            sb.append(' ');
        sb.append(' ');
        if (sb.length() > sizeLimit)
            break;
    }
    if (sb.length() <= sizeLimit)
        return sb.toString().trim();
    int i = 0;
    int last = -1;
    for (;;) {
        i = sb.indexOf(" ", i + 1);
        if (i == -1 || i > sizeLimit)
            break;
        last = i;
    }
    if (last == -1)
        last = sizeLimit;
    return sb.substring(0, last) + "";
}