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.HotelResultsSearchResultsFragment.java

License:Open Source License

public boolean selectResultByName(String neighborhoodName) {
    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")).getText().trim();
        resultName = resultName.split("\n")[0];
        if (resultName.equalsIgnoreCase(neighborhoodName)) {
            getWebDriver().navigate().to(href);
            return true;
        }/*from   ww  w.  j  a v  a  2  s . c  o m*/
    }
    return false;
}

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

License:Open Source License

public boolean selectResultWhoseNameContains(String subString) {
    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")).getText().trim();

        if (resultName.toLowerCase().contains(subString.toLowerCase())) {
            getWebDriver().navigate().to(href);
            return true;
        }/*  ww w.  jav  a2  s  .c  o  m*/
    }
    return false;
}

From source file:com.hotwire.selenium.desktop.us.search.AirSearchFragment.java

License:Open Source License

public ArrayList<String> getAttibutesForAutocomplete(String attributeName) {
    List<WebElement> autocompleteList = getAutoComplete().findElements(By.tagName("li"));
    ArrayList<String> autocompleteAttributes = new ArrayList<>();

    for (WebElement item : autocompleteList) {
        autocompleteAttributes.add(item.getAttribute(attributeName));
    }/*from w  ww. j a va2s.  com*/
    return autocompleteAttributes;

}

From source file:com.hotwire.selenium.desktop.us.search.CarSearchFragment.java

License:Open Source License

public ArrayList<String> getAttibutesForAutocomplete(String attributeName) {
    List<WebElement> autocompleteList = fareFinderForm
            .findElement(By.cssSelector(FARE_FINDER_AUTOCOMPLETE_CONTENT)).findElements(By.tagName("li"));
    ArrayList<String> autocompleteAttributes = new ArrayList<String>();

    for (WebElement item : autocompleteList) {
        autocompleteAttributes.add(item.getAttribute(attributeName));
    }/*  w ww.  ja  v  a2  s . c  o  m*/
    return autocompleteAttributes;

}

From source file:com.hotwire.selenium.desktop.us.search.HotelSearchFragment.java

License:Open Source License

public ArrayList<String> getAttibutesForAutocomplete(String attributeName) {
    List<WebElement> autocompleteList = fareFinderForm
            .findElement(cssSelector(FARE_FINDER_AUTOCOMPLETE_CONTENT)).findElements(By.tagName("li"));
    ArrayList<String> autocompleteAttributes = new ArrayList<>();

    for (WebElement item : autocompleteList) {
        autocompleteAttributes.add(item.getAttribute(attributeName));
    }/*from  w w  w . ja va  2s . co m*/
    return autocompleteAttributes;
}

From source file:com.hotwire.selenium.desktop.us.search.HotelSearchFragment.java

License:Open Source License

public ArrayList<String> getAutocompleteContents() {
    List<WebElement> autocompleteList = fareFinderForm
            .findElement(cssSelector(FARE_FINDER_AUTOCOMPLETE_CONTENT)).findElements(By.tagName("div"));
    ArrayList<String> autocompleteTextContents = new ArrayList<>();

    for (WebElement item : autocompleteList) {
        if ((item.getAttribute("title") != null) && !(item.getAttribute("title").equals(""))) {
            autocompleteTextContents.add(item.getAttribute("title").trim());
        } else {//from ww  w .j  ava  2 s .co m
            autocompleteTextContents.add(item.getText().trim());
        }
    }
    return autocompleteTextContents;
}

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

License:Open Source License

private static WebElement resolveToContainer(WebElement containerOrDescendantElement) {
    WebElement test = containerOrDescendantElement;
    while (test != null) {
        String cssClass = test.getAttribute("class");
        if (cssClass != null && (cssClass.contains("CalendarComp") || cssClass.contains("datepicker"))) {
            return test;
        }/*w  ww.j a v  a2 s  .com*/
        test = test.findElement(By.xpath(".."));
    }
    throw new RuntimeException("Could not find valid Calendar container based on input "
            + containerOrDescendantElement.toString());
}

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

License:Open Source License

public List<String> getValueList() {
    Select nativeDropDownSelector = new Select(nativeDropDown);
    List<String> valueList = new ArrayList<String>();
    for (WebElement option : nativeDropDownSelector.getOptions()) {
        valueList.add(option.getAttribute("value"));
    }/*from   w  w w .  ja  va  2 s. co m*/
    return valueList;
}

From source file:com.hotwire.selenium.mobile.account.MobileMyAccountPage.java

License:Open Source License

private WebElement getNavButtonByHrefSuffix(String hrefSuffix) {
    for (WebElement element : navButtons) {
        if (element.getAttribute("href").endsWith(hrefSuffix)) {
            return element;
        }/*w w w  .ja  v a 2s  .c om*/
    }
    throw new NoSuchElementException("No such navigation WebElement with href ending with " + hrefSuffix);
}

From source file:com.hotwire.selenium.mobile.results.MobileHotelResultsPage.java

License:Open Source License

public void filterByStarRating(String rating) {
    filterButton.click();//from  w  w  w  . j  a  v  a2 s. c o m
    for (WebElement element : starRatingFilters) {
        if (element.getAttribute("data-star").equals(rating)) {
            element.click();
            break;
        }
    }
    filterDoneButton.click();
}