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:io.selendroid.demo.webui.EmployeeDirectoryTest.java

License:Apache License

@Step("Verify the reportees of employee with id <id> are <reportees>")
public void verifyNumberOfDirectReports(String id, Table reportees) throws Exception {
    WebDriver driver = Driver.webDriver;

    List<TableRow> tableRows = reportees.getTableRows();
    for (int i = 0; i < tableRows.size(); i++) {
        Assert.assertThat(driver.findElements(By.tagName("li")).get(i).getText(),
                startsWith(tableRows.get(i).getCell("name")));
    }// w  w  w .ja va  2s. c om
    driver.navigate().back();

    Assert.assertEquals(driver.getCurrentUrl(), "file:///android_asset/www/index.html#employees/4");
}

From source file:io.wcm.qa.galenium.testcase.AbstractGaleniumInteractiveBaseTestCase.java

License:Apache License

protected void mouseOver(Selector selector) {
    getLogger().debug("attempting mouse over: " + selector.elementName());
    WebDriver driver = getDriver();
    List<WebElement> mouseOverElements = driver.findElements(selector.asBy());
    if (!mouseOverElements.isEmpty()) {
        WebElement mouseOverElement = mouseOverElements.get(0);
        if (mouseOverElement.isDisplayed()) {
            getLogger().debug("Moving to element: " + mouseOverElement);
            Actions actions = new Actions(driver);
            actions.moveToElement(mouseOverElement).perform();
        }/*from   ww  w.  j av a2 s  . c o m*/
    } else {
        getLogger().debug("no elements found.");
    }
}

From source file:io.wcm.qa.galenium.util.InteractionUtil.java

License:Apache License

/**
 * @param driver driver//from   w  ww .  j  ava  2  s  .  co m
 * @param selector used to find elements
 * @return list of elements matched by selector
 */
public static List<WebElement> findElements(WebDriver driver, Selector selector) {
    return driver.findElements(selector.asBy());
}

From source file:litecartAdmin.GeoZonesPageTest.java

@Parameters
public static Collection<Object[]> getAllUrl() {
    WebDriver driver = getDriver();
    (new AdminLoginPage(driver)).login();
    driver.get("http://litecart.resscode.org.ua/admin/?app=geo_zones&doc=geo_zones");
    List<WebElement> elems = driver.findElements(By.cssSelector(".row td:nth-child(3) a"));
    List<Object[]> hrefs = new ArrayList<Object[]>();
    elems.forEach((e) -> {//from  www .  ja v a2 s .  c  o  m
        hrefs.add(new Object[] { e.getAttribute("href") });
    });
    driver.quit();
    return hrefs;
}

From source file:main.java.qa.android.util.WaitTool.java

License:Open Source License

/**
  * Wait for the List<WebElement> to be present in the DOM, regardless of being displayed or not.
  * Returns all elements within the current page DOM. 
  * //from   w  w  w .  ja va 2s.  c  o m
  * @param WebDriver   The driver object to be used 
  * @param By   selector to find the element
  * @param int   The time in seconds to wait until returning a failure
  *
  * @return List<WebElement> all elements within the current page DOM, or null (if the timeout is reached)
  */
public static List<WebElement> waitForListElementsPresent(WebDriver driver, final By by, int timeOutInSeconds) {
    List<WebElement> elements;
    try {
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() 

        WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
        wait.until((new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver driverObject) {
                return areElementsPresent(driverObject, by);
            }
        }));

        elements = driver.findElements(by);
        driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait
        return elements; //return the element   
    } catch (Exception e) {
        Log.info(e.getMessage());
    }
    return null;
}

From source file:main.java.qa.android.util.WaitTool.java

License:Open Source License

/**
 * Checks if the List<WebElement> are in the DOM, regardless of being displayed or not.
 * /*from   w  w w  .j  a v a  2s . c  om*/
 * @param driver - The driver object to use to perform this element search
 * @param by - selector to find the element
 * @return boolean
 * @exception Exception e - addVerificationFailure(e);
 */
private static boolean areElementsPresent(WebDriver driver, By by) {
    try {
        driver.findElements(by);
        return true;
    } catch (NoSuchElementException e) {
        addVerificationFailure(e);
        Log.info(e.getMessage());
        return false;
    }
}

From source file:net.atf4j.webdriver.page.AbstractPageObject.java

License:Open Source License

/**
 * Search finished.//  w  w w. ja v a 2 s. c om
 *
 * @return the expected condition
 */
protected ExpectedCondition<Boolean> searchFinished() {
    return new ExpectedCondition<Boolean>() {

        /*
         * (non-Javadoc)
         *
         * @see com.google.common.base.Function#apply(java.lang.Object)
         */
        @Override
        public Boolean apply(final WebDriver webDriver) {
            final String xpathExpression = "";
            final List<WebElement> elements = webDriver.findElements(By.xpath(xpathExpression));
            return elements.size() >= 10;
        }
    };
}

From source file:net.integration.SeleniumUtils.java

License:Open Source License

public static WebElement findButtonByName(WebDriver webDriver, String name) {
    List<WebElement> elements = webDriver.findElements(By.tagName("button"));

    for (WebElement element : elements) {
        if (name.equals(element.getText()))
            return element;
    }//from  w  w  w  .  j a  v  a2 s . co  m

    return null;
}

From source file:net.integration.SeleniumUtils.java

License:Open Source License

public static WebElement findInputById(WebDriver webDriver, String id) {
    List<WebElement> elements = webDriver.findElements(By.tagName("input"));

    for (WebElement element : elements) {
        if (element.getAttribute("id").matches(".*:" + id + "$"))
            return element;
    }//  ww w.  j a  v a2 s.  c o m

    return null;
}

From source file:net.integration.SeleniumUtils.java

License:Open Source License

public static WebElement findLinkByText(WebDriver webDriver, String text) {
    List<WebElement> elements = webDriver.findElements(By.tagName("a"));

    for (WebElement element : elements) {
        if (text.equals(element.getText()))
            return element;
    }/* w w w.j av  a 2 s . c  o  m*/

    return null;
}