Example usage for org.openqa.selenium WebElement findElements

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

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:com.hack23.cia.systemintegrationtest.UserPageVisit.java

License:Apache License

/**
 * Gets the grid rows./*w w  w.j a  v  a 2  s. c  o m*/
 *
 * @return the grid rows
 */
public List<WebElement> getGridRows() {
    final WebElement gridBody = driver.findElement(By.className("v-grid-body"));
    return gridBody.findElements(By.className("v-grid-row"));

}

From source file:com.hack23.cia.systemintegrationtest.UserPageVisit.java

License:Apache License

/**
 * Gets the grid headers.//  w w  w.j av  a  2  s. c o m
 *
 * @return the grid headers
 */
public List<WebElement> getGridHeaders() {
    final WebElement gridBody = driver.findElement(By.className("v-grid-header"));

    return gridBody.findElements(By.className("v-grid-row"));

}

From source file:com.hotwire.selenium.angular.AngularHotelResultsPage.java

License:Open Source License

public int getAmenitiesFilterCount(String value) {
    if (!getWebDriver().findElement(By.cssSelector(AMENITIES_FILTER + " ul.dropdown-menu")).isDisplayed()) {
        amenitiesDropdown.click();/*from  w  w w .  j  a  va  2  s. c o  m*/
        new WebDriverWait(getWebDriver(), 2)
                .until(new VisibilityOf(By.cssSelector(AMENITIES_FILTER + " ul.dropdown-menu")));
    }
    for (WebElement element : getWebDriver()
            .findElements(By.cssSelector(AMENITIES_FILTER + " ul li a[data-bdd='amenityFilterItem']"))) {
        List<WebElement> spanElems = element.findElements(By.cssSelector("span span"));
        if (spanElems.get(0).getText().trim().equalsIgnoreCase(value)) {
            return new Integer(spanElems.get(spanElems.size() - 1).getText().replaceAll("[^\\d]", ""))
                    .intValue();
        }
    }
    throw new RuntimeException(value + " is not a valid amenity filter.");
}

From source file:com.hotwire.selenium.angular.AngularHotelResultsPage.java

License:Open Source License

public WebElement getFirstFilterableArea() {
    if (new InvisibilityOf(By.cssSelector(AREAS_FILTER + " ul.dropdown-menu")).apply(getWebDriver())) {
        areasDropdown.click();/*from   w  w w  .ja v a  2  s .  c o  m*/
        new WebDriverWait(getWebDriver(), 2)
                .until(new VisibilityOf(By.cssSelector(AREAS_FILTER + " ul.dropdown-menu")));
    }
    List<WebElement> areas = getWebDriver()
            .findElements(By.cssSelector(AREAS_FILTER + " ul.dropdown-menu  li a"));
    for (WebElement area : areas) {
        logger.info("AREA: " + area.getText());
        if (!area.getText().trim().toLowerCase().equals("all areas")) {
            List<WebElement> spans = area.findElements(By.cssSelector("span span"));
            if (new Integer(spans.get(spans.size() - 1).getText().trim().replaceAll("[^\\d]", ""))
                    .intValue() > 0) {
                return area;
            }
        }
    }
    return null;
}

From source file:com.hotwire.selenium.angular.AngularHotelResultsPage.java

License:Open Source License

public WebElement getFirstFilterableAmenity() {
    if (new InvisibilityOf(By.cssSelector(AMENITIES_FILTER + " ul.dropdown-menu")).apply(getWebDriver())) {
        amenitiesDropdown.click();/*from  w w  w .  ja va2s  .co m*/
    }
    new WebDriverWait(getWebDriver(), 2)
            .until(new VisibilityOf(By.cssSelector(AMENITIES_FILTER + " ul.dropdown-menu")));
    List<WebElement> amenities = getWebDriver()
            .findElements(By.cssSelector(AMENITIES_FILTER + " ul.dropdown-menu  li a"));
    for (WebElement amenity : amenities) {
        logger.info("AMENITY: " + amenity.getText());
        List<WebElement> spans = amenity.findElements(By.cssSelector("span span"));
        if (new Integer(spans.get(spans.size() - 1).getText().trim().replaceAll("[^\\d]", "")).intValue() > 0) {
            return amenity;
        }
    }
    return null;
}

From source file:com.hotwire.selenium.angular.AngularHotelResultsPage.java

License:Open Source License

public boolean areOptionsWithZeroCountDisabled(String filterType) {
    String root;// ww  w. j a va 2 s  .  com
    WebElement rootElement;
    if (filterType.equals("Areas")) {
        root = AREAS_FILTER;
        rootElement = areasDropdown;
    } else if (filterType.equals("Star Rating")) {
        root = STAR_RATING_FILTER;
        rootElement = starRatingDropdown;
    } else if (filterType.equals("Amenities")) {
        root = AMENITIES_FILTER;
        rootElement = amenitiesDropdown;
    } else {
        throw new UnimplementedTestException(filterType + " is not valid for this method.");
    }

    if (new InvisibilityOf(By.cssSelector(root + " ul.dropdown-menu")).apply(getWebDriver())) {
        rootElement.click();
    }
    new WebDriverWait(getWebDriver(), 2).until(new VisibilityOf(By.cssSelector(root + " ul.dropdown-menu")));
    List<WebElement> elements = getWebDriver().findElements(By.cssSelector(root + " ul.dropdown-menu li a"));

    ArrayList<WebElement> zeroCountElements = new ArrayList<WebElement>();
    int i = 5;
    for (WebElement element : elements) {
        logger.info("FILTER ELEMENT: " + (filterType.equals("Star Rating") ? i + " stars" : element.getText()));
        if (!filterType.equals("Star Rating")) {
            if (!(element.getText().trim().toLowerCase().equals("all areas")
                    || element.getText().trim().toLowerCase().equals("accessibility options"))) {
                List<WebElement> spans = element.findElements(By.cssSelector("span span"));
                if (new Integer(spans.get(spans.size() - 1).getText().trim().replaceAll("[^\\d]", ""))
                        .intValue() == 0) {
                    zeroCountElements.add(element);
                    List<String> searchList = getAllAreaNames();
                    element.click();
                    new WebDriverWait(getWebDriver(), 10).until(
                            new IsElementLocationStable(getWebDriver(), By.cssSelector(RESULTS_LIST), 4));
                    if (!searchList.equals(getAllAreaNames())) {
                        return false;
                    }
                }
            }
        } else {
            if (new Integer(element.findElement(By.cssSelector("span.resultCount")).getText().trim()
                    .replaceAll("[^\\d]", "")).intValue() == 0) {
                zeroCountElements.add(element);
                List<String> searchList = getAllAreaNames();
                element.click();
                new WebDriverWait(getWebDriver(), 5)
                        .until(new IsElementLocationStable(getWebDriver(), By.cssSelector(RESULTS_LIST), 4));
                if (!searchList.equals(getAllAreaNames())) {
                    return false;
                }
            }
            --i;
        }
    }
    logger.info("ZERO COUNT: " + zeroCountElements.size());
    if (zeroCountElements.size() == 0) {
        throw new ZeroResultsTestException("Areas filter has 0 options with 0 count.");
    }
    return true;
}

From source file:com.hotwire.selenium.angular.AngularHotelResultsPage.java

License:Open Source License

public ArrayList<String> getAllResultsAmenitiesList() {
    ArrayList<String> amenities = new ArrayList<String>();
    if (0 == resultsList.size()) {
        throw new ZeroResultsTestException("Angular hotel results page: 0 results returned.");
    }//from   w  ww.  ja  v  a 2  s.c  om
    for (WebElement result : getWebDriver().findElements(By.cssSelector(RESULTS_LIST + " ul.amenities"))) {
        List<String> text = new ArrayList<String>();
        for (WebElement list : result.findElements(By.cssSelector("li"))) {
            text.add(list.getText().trim());
        }
        if (text.size() > 0) {
            amenities.add(StringUtils.join(text, " ").trim());
        }
    }
    return amenities;
}

From source file:com.hotwire.selenium.bex.hotel.search.HotelSearchPage.java

License:Open Source License

public void selectProxDates() {
    if (startDateField != null) {

        startDateField.click();/*w  w  w .  ja  v  a 2s  .c o m*/
        WebElement dateWidget = getWebDriver().findElement(By.xpath("//ul[@class='cal-dates']"));
        List<WebElement> options = dateWidget.findElements(By.tagName("li"));
        for (WebElement opt : options) {
            try {
                opt.findElement(By.tagName("a"));
                opt.click();
                break;
            } catch (NoSuchElementException e) {
                LOGGER.info("date was not clickable");
            }
        }
    }
}

From source file:com.hotwire.selenium.bex.hotel.search.HotelSearchPage.java

License:Open Source License

public void selectFarDates() {
    if (startDateField != null) {

        startDateField.click();//from w w w  . j av  a  2s . c  om
        getWebDriver().findElement(By.xpath("//button[@class='btn-paging btn-secondary next']")).click();
        WebElement dateWidget = getWebDriver().findElement(By.xpath("//ul[@class='cal-dates']"));
        List<WebElement> options = dateWidget.findElements(By.tagName("li"));
        for (WebElement opt : options) {
            try {
                opt.findElement(By.tagName("a"));
                opt.click();
                break;
            } catch (NoSuchElementException e) {
                LOGGER.info("date not clickable");
            }
        }
    }
}

From source file:com.hotwire.selenium.desktop.details.HotelDetailsPage.java

License:Open Source License

public List<SearchSolution> getCrossSellsList() {
    List<SearchSolution> crossSellList = new ArrayList<SearchSolution>();
    int number = 0;

    for (WebElement result : getWebDriver().findElements(By.cssSelector(
            "div.opaqueDetailsCrossSell a, .crossSellDeal a, .hotelCrossSell a, .priceHoodContent"))) {
        SearchSolution searchSolution = new SearchSolution();
        searchSolution.setNumber(number++);
        String dealData = result.getText();
        searchSolution.setDealData(dealData);
        boolean isSingleCrossSell = result.findElements(By.cssSelector(".stackedLayout")).size() > 0;
        if (!isSingleCrossSell) {
            try {
                searchSolution.setPrice(result.findElement(By.cssSelector(".price")).getText().trim());
                searchSolution/*from  w ww  .j a  v  a2 s  .c  om*/
                        .setHotelName(result.findElement(By.cssSelector(".neighborhoodName")).getText().trim());
            } catch (WebDriverException e) {
                searchSolution.setPrice(
                        result.findElements(By.cssSelector("span ul li")).get(3).getText().split("\\D+")[1]
                                .trim());
                searchSolution.setHotelName(
                        result.findElements(By.cssSelector("span ul li")).get(1).getText().trim());
            }

        } else {
            // XSD13=1 cross sell.
            WebElement singleOpaqueXsell = result.findElement(By.cssSelector(".stackedLayout"));
            searchSolution.setPrice(
                    singleOpaqueXsell.findElements(By.cssSelector(".heading strong")).get(1).getText().trim());
            searchSolution.setHotelName("stackedLayout");
        }
        crossSellList.add(searchSolution);
    }
    return crossSellList;
}