Example usage for org.openqa.selenium WebElement getAttribute

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

Introduction

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

Prototype

String getAttribute(String name);

Source Link

Document

Get the value of the given attribute of the element.

Usage

From source file:com.hotwire.selenium.desktop.us.results.hotel.fragments.filters.HotelResultsAmenitiesFilteringTabPanelFragment.java

License:Open Source License

public void uncheckAmenityByName(String amenityName) {
    for (WebElement element : allNonAccessibleAmenities) {
        if (element.getAttribute("amenityname").equals(amenityName) && element.isSelected()) {
            element.click();/*from ww w. j  av  a 2 s  . c  o  m*/
            doWaitForUpdatingLayer();
            break;
        }
    }
}

From source file:com.hotwire.selenium.desktop.us.results.hotel.fragments.tripwatcher.HotelResultsTripwatcherLayerFragment.java

License:Open Source License

public boolean isTripWatcherLayerFromSpeedBump() {
    for (WebElement element : getWebDriver().findElements(By.cssSelector(TRIP_WATCHER_LAYER))) {
        if (element.isDisplayed()) {
            if (element.getAttribute("id").equals("speedBumpTripWatcherLayer-layer")) {
                return true;
            }// w  ww. ja va 2 s  .  com
        }
    }
    return false;
}

From source file:com.hotwire.selenium.desktop.us.results.hotel.fragments.tripwatcher.HotelResultsTripwatcherLayerFragment.java

License:Open Source License

public WebElement getVisibleTripWatcherSubscribeButton() {
    for (WebElement element : getWebDriver().findElements(By.cssSelector(SUBSCRIBE))) {
        if (element.isDisplayed()) {
            logger.info("Visible button element id: " + element.getAttribute("class"));
            return element;
        }/*w  w w.j  a  v  a  2s  .  c  o m*/
    }
    throw new RuntimeException("TripWatcher email not visible for use.");
}

From source file:com.hotwire.selenium.desktop.us.results.hotel.fragments.tripwatcher.HotelResultsTripwatcherLayerFragment.java

License:Open Source License

public WebElement getVisibleTripWatcherEmailElement() {
    for (WebElement element : getWebDriver().findElements(By.cssSelector(EMAIL))) {
        if (element.isDisplayed()) {
            logger.info("Visible email element id: " + element.getAttribute("id"));
            return element;
        }/*from  w ww . j  a va2s . c  om*/
    }
    throw new RuntimeException("TripWatcher email not visible for use.");
}

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

License:Open Source License

public void select(Integer resultNumberToSelect) {
    HotelResultsSearchResultsFragment resultsFragment = getSearchResultsFragment();
    if (resultsFragment.getSearchResultsHrefList().size() == 0) {
        throw new ZeroResultsTestException("0 hotel search results returned.");
    }/*from w  ww. ja v a 2  s . c om*/
    WebElement selectedHotelResult = resultsFragment.getResultsHrefsElements().get(resultNumberToSelect);
    if (opaqueResultsAreDisplayed()) {
        selectedHotelResult.click();
    } else {
        // HACK! for retail results issue clicking result item.
        getWebDriver().navigate().to(selectedHotelResult.getAttribute("href"));
    }
}

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

License:Open Source License

public String getHotelSearchId() {
    WebElement searchIdElement = getWebDriver()
            .findElement(By.cssSelector("form[id='hotel-sort'] input[id='resolvedSearchId']"));
    return searchIdElement.getAttribute("value");
}

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

License:Open Source License

/**
 * Get href's of search results./*from ww w .j  a v  a2 s.  c  o  m*/
 */
public List<String> getSearchResultsHrefList() {
    ArrayList<String> itemHrefs = new ArrayList<String>();
    for (WebElement resultHref : getResultsHrefsElements()) {
        String href = resultHref.getAttribute("href").toString().trim();
        itemHrefs.add(href);
    }
    return itemHrefs;
}

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

License:Open Source License

public List<String> getAccessibilitySearchResultsHrefList() {
    ArrayList<String> itemHrefs = new ArrayList<String>();
    if (resultBodies.size() == 0) {
        throw new ZeroResultsTestException("0 results returned from search.");
    }/*  w  w w.  ja va 2 s.com*/
    List<WebElement> resultsItems = getWebDriver().findElement(By.cssSelector(HOTEL_RESULTS_LIST_CLASS))
            .findElements(By.cssSelector("li .singleResult"));
    for (WebElement result : resultsItems) {
        WebElement hrefElement = result.findElement(By.cssSelector("a.hotelNameLink"));
        String href = hrefElement.getAttribute("href");
        String resultName = result.findElement(By.cssSelector(".neighborhoodName span[id='hotelOrHoodName']"))
                .getText().trim();
        try {
            String elements = result.findElement(By.cssSelector(".resultAmenities"))
                    .getAttribute("data-amenities");
            ArrayList<String> labels = new ArrayList<String>();
            LOGGER.info("AMENITIES CODE STRING: " + elements);
            for (String item : elements.split("\\|")) {
                if (accessibilityCodesMap.containsKey(item)) {
                    String text = accessibilityCodesMap.get(item);
                    labels.add(text);
                }
            }
            if (labels.size() == 0) {
                LOGGER.info(resultName + " has no accessibility amenities.");
            } else {
                itemHrefs.add(href);
                String amenityLabels = StringUtils.join(labels.toArray(), ", ");
                LOGGER.info(resultName + " accessibility amenities: " + amenityLabels);
            }
        } catch (NoSuchElementException e) {
            LOGGER.info(resultName + " has no amenities listed.");
        }
    }
    return itemHrefs;
}

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

License:Open Source License

public ArrayList<String> getStarRatingsTexts() {
    ArrayList<String> texts = new ArrayList<String>();
    for (WebElement rating : searchResultsStarRatings) {
        String text = rating.getAttribute("title").trim();
        if (!text.equals("")) {
            texts.add(text);/*from  w  w w  .  j a v a 2 s  .c  o  m*/
        }
    }
    return texts;
}

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

License:Open Source License

@SuppressWarnings("unused")
public boolean clickSolutionByNeighborhoodStarRatingAndCrs(String neighborhood, String starRating, String crs) {
    if (getWebDriver().getCurrentUrl().contains("preprod")) {
        crs = "null";
    }/*from w w  w . j av a 2s  . c o  m*/
    List<WebElement> elements = getWebDriver().findElements(By.cssSelector("li div.singleResult"));
    for (WebElement element : elements) {
        WebElement href = element.findElement(By.cssSelector("a.hotelNameLink"));
        WebElement refNoCrsElement = element.findElement(By.cssSelector("a.detailsLink"));
        String refNoText = refNoCrsElement.getAttribute("data-refnumber").trim();
        String crsText = refNoCrsElement.getAttribute("data-debuginfo").trim();
        String neighborhoodText = element
                .findElement(By.cssSelector(".neighborhoodName span[id='hotelOrHoodName']")).getText().trim();
        String starRatingText = element.findElement(By.cssSelector(".starsAmount")).getAttribute("title")
                .split(" ")[0];
        LOGGER.info("NEIGHBORHOOD: " + neighborhoodText + "  - CRS: " + crsText + " - STAR RATING: "
                + starRatingText);
        if (neighborhoodText.equalsIgnoreCase(neighborhood) && starRatingText.equals(starRating)
                && crsText.trim().equalsIgnoreCase(crs)) {
            LOGGER.info("Solution found: " + neighborhoodText + " - " + starRatingText + " - " + crsText);
            refNoCrsElement.click();
            return true;
        }
    }
    return false;
}