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.hotwire.selenium.desktop.seo.InformationPageUS.java

License:Open Source License

private ArrayList<WebElement> getColumnUrlsWebElements(boolean getLeftColumn, String vertical) {
    WebElement leftColumn = null;
    WebElement rightColumn = null;/*from   w  ww.j ava  2 s  .c o m*/

    if ("hotel".equalsIgnoreCase(vertical)) {
        leftColumn = hotelLeftColumn;
        rightColumn = hotelRightColumn;
    } else if ("car".equalsIgnoreCase(vertical)) {
        leftColumn = carLeftColumn;
        rightColumn = carRightColumn;
    } else if ("flight".equalsIgnoreCase(vertical)) {
        leftColumn = flightLeftColumn;
        rightColumn = flightRightColumn;

    }

    ArrayList<WebElement> hrefs = new ArrayList<WebElement>();
    List<WebElement> aTags = null;
    try {
        if (getLeftColumn) {
            aTags = leftColumn.findElements(By.tagName("a"));

        } else {
            aTags = rightColumn.findElements(By.tagName("a"));
        }
    } catch (NoSuchElementException e) {
        e.printStackTrace();
    }

    if (null != aTags) {
        hrefs.addAll(aTags);
    }

    return hrefs;
}

From source file:com.hotwire.selenium.desktop.us.HomePage.java

License:Open Source License

public Map<String, String> selectHotelDeal() {
    Map<String, String> map = new HashMap<>();
    if (getWebDriver().findElements(By.cssSelector(".deals ul .deal")).size() > 0) {
        // New home page deals.
        WebElement deal = getWebDriver().findElement(By.cssSelector(".deals ul .deal"));
        map.put("price", deal.findElement(By.cssSelector(".description .price")).getText().trim());
        map.put("location", deal.findElement(By.cssSelector(".description .location")).getText().trim());
        map.put("rating", deal.findElement(By.cssSelector(".description .ratings")).getText().trim());
        if (new GlobalHeader(getWebDriver()).hasVerticalNavigationTabs()
                && deal.findElements(By.cssSelector(".description .savings")).size() > 0) {
            map.put("savings", deal.findElement(By.cssSelector(".description .savings")).getText().trim()
                    .split("\\s+")[0]);
        }/* w w  w  .j  ava  2  s . c om*/
        deal.findElement(By.tagName("a")).click();
        new HotelResultsPage(getWebDriver());
        return map;
    }
    WebElement tr = getWebDriver().findElement(By.cssSelector("table.hotel.dealsTable tbody tr"));
    for (WebElement td : tr.findElements(By.cssSelector("td"))) {
        map.put(td.getAttribute("class"), td.getText());
    }
    tr.click();
    return map;
}

From source file:com.hotwire.selenium.desktop.us.index.HotelIndexPage.java

License:Open Source License

public Map<String, String> selectHotelDeal() {
    Map<String, String> map = new HashMap<>();
    WebElement tr = hotelDeals.get(0);
    if (tr.getAttribute("class").contains("deal")) {
        // New happy home page deal module.
        map.put("price", tr.findElement(By.cssSelector(".description .price")).getText().trim());
        map.put("location", tr.findElement(By.cssSelector(".description .location")).getText().trim());
        map.put("rating", tr.findElement(By.cssSelector(".description .ratings")).getText().trim());
        if (currentlyOnDomesticSite() && tr.findElements(By.cssSelector(".description .savings")).size() > 0) {
            map.put("savings",
                    tr.findElement(By.cssSelector(".description .savings")).getText().trim().split("\\s+")[0]);
        }/*from w w w  .  j a  va2  s . c  om*/
        tr.findElement(By.tagName("a")).click();
        new HotelResultsPage(getWebDriver());
        return map;
    }
    for (WebElement td : tr.findElements(By.cssSelector("span"))) {
        map.put(td.getAttribute("class"), td.getText());
    }
    tr.click();
    return map;
}

From source file:com.hotwire.selenium.desktop.us.results.AirResultsPage.java

License:Open Source License

public ArrayList<Double> getAllSolutionsPrices() {
    ArrayList<Double> prices = new ArrayList<Double>();
    for (WebElement priceLookup : priceLookups) {
        if (priceLookup.findElements(By.cssSelector(".dollars")).isEmpty()) {
            continue;
        }/*from  w  ww  .  ja v a  2s  .  co m*/
        String price = priceLookup.findElement(By.cssSelector(".dollars")).getText().trim() + "."
                + priceLookup.findElement(By.cssSelector(".cents")).getText().trim();
        prices.add(new Double(price.replaceAll("[^0-9.]", "")));
    }
    return prices;
}

From source file:com.hotwire.selenium.desktop.us.results.AirResultsPage.java

License:Open Source License

public ArrayList<LocalTime> getOriginDepartureTimeList() {
    ArrayList<LocalTime> originDepartureTimeList = new ArrayList<>();
    for (WebElement originDepartureTime : originDepartureTimes) {
        if (originDepartureTime.findElements(By.cssSelector(".time")).isEmpty()) {
            continue;
        }//www. j a  v  a 2  s  . c o  m
        String text = originDepartureTime.findElement(By.cssSelector(".time")).getText().trim();
        originDepartureTimeList.add(LocalTime.parse(text, DateTimeFormat.shortTime()));
    }
    return originDepartureTimeList;
}

From source file:com.hotwire.selenium.desktop.us.results.AirResultsPage.java

License:Open Source License

public ArrayList<LocalTime> getDepartureDestinationTimesList() {
    ArrayList<LocalTime> destinationDepartureTimeList = new ArrayList<LocalTime>();
    for (WebElement departureDestinationTime : departureDestinationTimes) {
        if (departureDestinationTime.findElements(By.cssSelector(".time")).isEmpty()) {
            continue;
        }//w ww  .ja v  a2s. c  om
        String text = departureDestinationTime.findElement(By.cssSelector(".time")).getText().trim();
        LocalTime localTime = LocalTime.parse(text, DateTimeFormat.shortTime());
        if (departureDestinationTime.findElements(By.cssSelector(".plusDay")).size() > 0) {
            int plusDays = new Integer(departureDestinationTime.findElement(By.cssSelector(".plusDay"))
                    .getText().trim().replaceAll("[^0-9]", "")).intValue();
            localTime = localTime.plusMillis(plusDays);
        }
        destinationDepartureTimeList.add(localTime);
    }
    return destinationDepartureTimeList;
}

From source file:com.hotwire.selenium.desktop.us.results.AirResultsPage.java

License:Open Source License

public ArrayList<Integer> getTotalNumberOfStopsPerSolution() {
    ArrayList<Integer> stops = new ArrayList<Integer>();
    for (WebElement solution : getWebDriver().findElements(By.cssSelector(".airSolution"))) {
        if (solution.findElements(By.cssSelector(".numStops")).isEmpty()) {
            continue;
        }/*w w w.j a  va2  s  . c  om*/
        String dtime = solution.findElement(By.cssSelector(".departure .numStops")).getText().trim();
        String atime = solution.findElement(By.cssSelector(".arrival .numStops")).getText().trim();
        Integer departureStop = dtime.equals("Nonstop") ? 0 : new Integer(dtime.replaceAll("[^0-9]", ""));
        Integer arrivalStop = atime.equals("Nonstop") ? 0 : new Integer(atime.replaceAll("[^0-9]", ""));
        stops.add(departureStop.intValue() + arrivalStop.intValue());
    }
    return stops;
}

From source file:com.hotwire.selenium.desktop.us.results.AirResultsPage.java

License:Open Source License

public ArrayList<Double> getTotalDurationPerSolution() {
    ArrayList<Double> durations = new ArrayList<Double>();
    for (WebElement solution : getWebDriver().findElements(By.cssSelector(".airSolution"))) {
        if (solution.findElements(By.cssSelector(".duration")).isEmpty()) {
            continue;
        }/*w ww. j av  a 2 s .  c  om*/
        String dduration = solution.findElement(By.cssSelector(".departure .duration")).getText().trim();
        String aduration = solution.findElement(By.cssSelector(".arrival .duration")).getText().trim();
        String[] dparts = dduration.split(" ");
        String[] aparts = aduration.split(" ");
        Double dHour = new Double(dparts[0].replaceAll("[^0-9]", ""));
        Double dMin = new Double(dparts[1].replaceAll("[^0-9]", "")) / 60.0;
        Double aHour = new Double(aparts[0].replaceAll("[^0-9]", ""));
        Double aMin = new Double(aparts[1].replaceAll("[^0-9]", "")) / 60.0;
        durations.add(new Double(new DecimalFormat("###.##")
                .format(dHour.doubleValue() + dMin.doubleValue() + aHour.doubleValue() + aMin.doubleValue())));
    }
    return durations;
}

From source file:com.hotwire.selenium.desktop.widget.AutoComplete.java

License:Open Source License

List<WebElement> getCandidates() {
    try {//from  w  ww .  j  a va2s  .  co  m

        WebElement container = getCandidateContainer();

        new WebDriverWait(webDriver, AUTOCOMPLETE_DISPLAY_TIMEOUT_SECONDS, AUTOCOMPLETE_POLLING_TIMEOUT_MS)
                .until(ExpectedConditions.visibilityOf(container));

        List<WebElement> out = container.findElements(AUTOCOMPLETE_CANDIDATES);
        LOGGER.info("candidates: {}", out.size());

        int total = 0;
        for (WebElement elm : out) {
            String innerText = elm.getText();
            if (StringUtils.isNoneBlank(innerText)) {
                LOGGER.info("{}", innerText);
                total++;
            }
        }

        LOGGER.info("Found {} candidates..", total);

        if (total > 0) {
            return out;
        }
    } catch (NoSuchElementException | TimeoutException e) {
        LOGGER.info("Autocomplete layout didn't appear..");
    }
    return null;
}

From source file:com.hotwire.selenium.desktop.widget.ErrorMessenger.java

License:Open Source License

public List<String> getMessages() {
    List<String> messages = new ArrayList<>();
    List<WebElement> webElementList = getMessageBlock();

    if (messageType.toString().equals("priceCheck")) {
        for (WebElement blk : webElementList) {
            if (blk.isDisplayed()) {
                messages.add(blk.getText().trim());
            }//from w  w w . j a  v  a2  s .  co  m
        }
    } else {
        for (WebElement blk : webElementList) {
            if (blk.isDisplayed()) {
                for (WebElement el : blk.findElements(By.cssSelector("ul li"))) {
                    messages.add(el.getText().trim());
                }
            }
        }
    }
    return messages;
}