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.billing.onepage.HotelBillingOnePage.java

License:Open Source License

public String getSelectedPaymentMethodIDValue() {
    for (WebElement element : getWebDriver()
            .findElements(By.cssSelector(".selectPaymentMethod .cardMethod input.radioBtn"))) {
        if (element.isSelected()) {
            return element.getAttribute("id").trim();
        }/*  w  ww . j a  v a  2s .  c o m*/
    }
    throw new RuntimeException("Could not find the payment method that was selected.");
}

From source file:com.hotwire.selenium.desktop.us.billing.PaymentMethodFragment.java

License:Open Source License

private boolean isNewPaymentType(WebElement paymentTypeRadio) {
    return paymentTypeRadio.getAttribute("value").equals("0");
}

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  av  a2 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.AirIndexPage.java

License:Open Source License

public boolean isMesoBannersVisible() {
    WebElement mesoLeft;
    WebElement mesoRight;//from www .  j ava  2  s . co  m
    try {
        mesoLeft = getWebDriver().findElement(By.id("LEFT1"));
        mesoRight = getWebDriver().findElement(By.id("RIGHT1"));
    } catch (NoSuchElementException e) {
        return false;
    }

    return mesoLeft.getAttribute("data-displayed").equals("true")
            || mesoLeft.getAttribute("data-loaded").equals("true")
            || mesoRight.getAttribute("data-displayed").equals("true")
            || mesoRight.getAttribute("data-loaded").equals("true");

}

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 ww w.j  ava  2 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 boolean sortResultsBy(String sortName) {
    WebElement sortElement;
    if (sortName.equalsIgnoreCase("price")) {
        sortElement = sortBar.findElement(By.cssSelector("a.price"));
        sortElement.click();/*from  ww w  .jav  a 2  s .  co m*/
        waitForUpdatingResults();
        new AirResultsPage(getWebDriver());
        sortElement = sortBar.findElement(By.cssSelector("a.price"));
        return sortElement.getAttribute("class").contains("asc") ? true : false;
    } else if (sortName.equalsIgnoreCase("departure")) {
        sortElement = sortBar.findElement(By.cssSelector("a.departure"));
        sortElement.click();
        waitForUpdatingResults();
        new AirResultsPage(getWebDriver());
        sortElement = sortBar.findElement(By.cssSelector("a.departure"));
        return sortElement.getAttribute("class").contains("asc") ? true : false;
    } else if (sortName.equalsIgnoreCase("arrival")) {
        sortElement = sortBar.findElement(By.cssSelector("a.arrival"));
        sortElement.click();
        waitForUpdatingResults();
        new AirResultsPage(getWebDriver());
        sortElement = sortBar.findElement(By.cssSelector("a.arrival"));
        return sortElement.getAttribute("class").contains("asc") ? true : false;
    } else if (sortName.equalsIgnoreCase("stops")) {
        sortElement = sortBar.findElement(By.cssSelector("a.stops"));
        sortElement.click();
        waitForUpdatingResults();
        new AirResultsPage(getWebDriver());
        sortElement = sortBar.findElement(By.cssSelector("a.stops"));
        return sortElement.getAttribute("class").contains("asc") ? true : false;
    } else if (sortName.equalsIgnoreCase("duration")) {
        sortElement = sortBar.findElement(By.cssSelector("a.duration"));
        sortElement.click();
        waitForUpdatingResults();
        new AirResultsPage(getWebDriver());
        sortElement = sortBar.findElement(By.cssSelector("a.duration"));
        return sortElement.getAttribute("class").contains("asc") ? true : false;
    }
    throw new UnimplementedTestException("Unknown Air results sort criteria.");
}

From source file:com.hotwire.selenium.desktop.us.results.car.fragments.compareWith.CompareWithFragment.java

License:Open Source License

public boolean verifyAllPartnersState(boolean state) {
    for (WebElement elm : partnerCheckboxes) {
        if (state != elm.isSelected()) {
            String status = state ? "selected" : "deselected";
            logger.warn("Checkbox of <" + elm.getAttribute("name") + "> wasn't " + status);
            return false;
        }/*from   w w  w . j av a  2s  . co  m*/
    }
    return true;
}

From source file:com.hotwire.selenium.desktop.us.results.car.impl.CarResultsPageTemplate.java

License:Open Source License

public boolean isMeSoBannersDisplayed() {
    WebElement banner1;
    WebElement banner2;//from   w w w.  java  2s  .co  m
    try {
        banner1 = getWebDriver().findElement(By.id("carResBan1"));
        banner2 = getWebDriver().findElement(By.id("carResBan2"));
    } catch (NoSuchElementException e) {
        return false;
    }

    return banner1.getAttribute("data-displayed").equals("true")
            || banner1.getAttribute("data-loaded").equals("true")
            || banner2.getAttribute("data-displayed").equals("true")
            || banner2.getAttribute("data-loaded").equals("true");
}

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

License:Open Source License

@Override
public void checkFirstFilteringCheckbox() {
    for (WebElement element : filteringCheckboxes) {
        if (element.getAttribute("disabled") == null && !element.isSelected()) {
            element.click();// ww w .  j ava2  s.  com
            doWaitForUpdatingLayer();
            break;
        }
    }
}

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

License:Open Source License

public void checkAmenityByName(String amenityName) {
    int i = 1;/*from w  w  w. j  a v  a 2s  . com*/
    for (WebElement element : allNonAccessibleAmenities) {
        LOGGER.info(">>>>> " + (i++) + ": " + element.getAttribute("id"));
        if (element.getAttribute("amenityname").equals(amenityName) && !element.isSelected()) {
            JavascriptExecutor javascriptExecutor = (JavascriptExecutor) getWebDriver();
            javascriptExecutor.executeScript("$(arguments[0]).focus()", element);
            element.click();
            doWaitForUpdatingLayer();
            break;
        }
    }
}