Example usage for org.openqa.selenium WebDriver findElements

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

Introduction

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

Prototype

@Override
List<WebElement> findElements(By by);

Source Link

Document

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

Usage

From source file:org.jspringbot.keyword.selenium.ElementFinder.java

License:Open Source License

public static WebElement findByTag(WebDriver driver, String tag, String tagName,
        Map<String, String> attributes) {
    return filterElements(driver.findElements(By.tagName(tag)), tagName, attributes);
}

From source file:org.jspringbot.keyword.selenium.ElementFinder.java

License:Open Source License

public static WebElement findByLinkText(WebDriver driver, String linkText, String tagName,
        Map<String, String> attributes) {
    return filterElements(driver.findElements(By.linkText(linkText)), tagName, attributes);
}

From source file:org.jspringbot.keyword.selenium.ElementFinder.java

License:Open Source License

public static WebElement findByPartialLinkText(WebDriver driver, String linkText, String tagName,
        Map<String, String> attributes) {
    return filterElements(driver.findElements(By.partialLinkText(linkText)), tagName, attributes);
}

From source file:org.jspringbot.keyword.selenium.ElementFinder.java

License:Open Source License

public static WebElement findByCSS(WebDriver driver, String cssSelector, String tagName,
        Map<String, String> attributes) {
    return filterElements(driver.findElements(By.cssSelector(cssSelector)), tagName, attributes);
}

From source file:org.kie.page.objects.ServerManagement.java

License:Apache License

private void generateActions(WebDriver driver) {
    List<WebElement> actions = driver.findElements(By.tagName("a"));
    for (WebElement action : actions) {
        String innerHTML = action.getAttribute("innerHTML");
        if (innerHTML.contains("Register")) {
            register = action;/* w w  w .  j a  v a  2s .co  m*/
        }
    }
}

From source file:org.kie.smoke.wb.selenium.util.LoadingIndicator.java

License:Apache License

public void disappear(String msg) {
    final By loadingIndicator = By.xpath("//div[@class='gwt-Label'][contains(.,'" + msg + "')]");
    new WebDriverWait(driver, 10).until(new Predicate<WebDriver>() {
        @Override/*  ww  w .j a  v a2s.co  m*/
        public boolean apply(WebDriver driver) {
            return driver.findElements(loadingIndicator).isEmpty();
        }
    });
}

From source file:org.kuali.kra.test.infrastructure.KcSeleniumHelper.java

License:Educational Community License

/**
 * Waits for the form to load by checking for the existence of "formComplete."
 *///from w ww . j av a 2s  . c  om
private void waitForFormLoad() {
    new ElementExistsWaiter("Page did not load").until(new Function<WebDriver, Boolean>() {
        public Boolean apply(WebDriver driver) {
            boolean isFormComplete = false;

            List<WebElement> elements = driver.findElements(By.id("formComplete"));
            if (CollectionUtils.isNotEmpty(elements)) {
                isFormComplete = true;
            }

            return isFormComplete;
        }
    });
}

From source file:org.kuali.rice.testtools.selenium.WebDriverUtils.java

License:Educational Community License

public static void highlightElement(WebDriver webDriver, By by) {
    List<WebElement> elements = webDriver.findElements(by);
    for (WebElement element : elements) {
        WebDriverUtils.highlightElement(webDriver, element);
    }//from w ww .ja  v a  2  s  .co m
}

From source file:org.kuali.rice.testtools.selenium.WebDriverUtils.java

License:Educational Community License

/**
 * <p>/*from  w w  w  .java2s. co  m*/
 * Wait for the given amount of seconds, for the given by, using the given driver.  The message is displayed if the
 * by cannot be found.  No action is performed on the by, so it is possible that the by found is not visible or enabled.
 * </p>
 *
 * @param driver WebDriver to wait on
 * @param waitSeconds seconds to wait
 * @param by By to wait for
 * @param message to display if by is not found in waitSeconds
 * @throws InterruptedException
 */
public static WebElement waitFor(WebDriver driver, int waitSeconds, By by, String message)
        throws InterruptedException {
    // jenkins implies that implicitlyWait is worse than sleep loop for finding elements by 100+ test failures on the old sampleapp
    //        driver.manage().timeouts().implicitlyWait(waitSeconds, TimeUnit.SECONDS);
    //        driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);

    driver.manage().timeouts().implicitlyWait(IMPLICIT_WAIT_TIME_LOOP_MS, TimeUnit.MILLISECONDS);

    boolean failed = false;
    WebElement element = null;

    for (int second = 0;; second++) {
        Thread.sleep(1000);
        if (second >= waitSeconds) {
            failed = true;
        }
        try {
            if (failed) {
                break;
            } else if ((driver.findElements(by)).size() > 0) {
                element = findElement(driver, by); // NOTICE just the find, no action, so by is found, but might not be visible or enabled.
                highlightElement(driver, element);
                break;
            }
        } catch (Exception e) {
        }
    }

    driver.manage().timeouts().implicitlyWait(configuredImplicityWait(), TimeUnit.SECONDS);
    return element;
}

From source file:org.kuali.rice.testtools.selenium.WebDriverUtils.java

License:Educational Community License

/**
 * <p>//from   w w w. j a v  a  2  s . c om
 * Wait for the given amount of seconds, for the given by, using the given driver.  The message is displayed if the
 * by cannot be found.  No action is performed on the by, so it is possible that the by found is not visible or enabled.
 * </p>
 *
 * @param driver WebDriver to wait on
 * @param waitSeconds seconds to wait
 * @param by By to wait for
 * @param message to display if by is not found in waitSeconds
 * @return List of WebElements found
 * @throws InterruptedException
 */
public static List<WebElement> waitFors(WebDriver driver, int waitSeconds, By by, String message)
        throws InterruptedException {
    // jenkins implies that implicitlyWait is worse than sleep loop for finding elements by 100+ test failures on the old sampleapp
    //        driver.manage().timeouts().implicitlyWait(waitSeconds, TimeUnit.SECONDS);
    //        driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);

    driver.manage().timeouts().implicitlyWait(IMPLICIT_WAIT_TIME_LOOP_MS, TimeUnit.MILLISECONDS);

    boolean failed = false;

    for (int second = 0;; second++) {
        Thread.sleep(1000);
        if (second >= waitSeconds) {
            failed = true;
        }
        try {
            if (failed || (driver.findElements(by)).size() > 0) {
                break;
            }
        } catch (Exception e) {
        }
    }

    driver.manage().timeouts().implicitlyWait(configuredImplicityWait(), TimeUnit.SECONDS);
    return driver.findElements(by); // NOTICE just the find, no action, so by is found, but might not be visible or enabled.
}