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.ecofactor.qa.automation.insite.page.UploadOneUserImpl.java

License:Open Source License

/**
 * @param fieldName//from  w  w w.  ja va 2 s .c  om
 * @see com.ecofactor.qa.automation.insite.page.UploadOneUser#validateAndSubmitForm(java.lang.String)
 */
@Override
public void validateAndSubmitForm(String fieldName) {

    DriverConfig.setLogString("Validate form data and click upload user.", true);
    WebElement error = null;

    DriverConfig.getDriver().findElement(By.id("uploadUser")).click();
    largeWait();

    switch (fieldName) {
    case "PastInstallationDate":
        Assert.assertTrue(DriverConfig.getDriver().findElement(By.id("uploadError")).getText()
                .equalsIgnoreCase("Validator Errors found: Installation date is in the past."));
        break;
    case "FutureCreatedDate":
        Assert.assertTrue(DriverConfig.getDriver().findElement(By.id("uploadError")).getText()
                .equalsIgnoreCase("Validator Errors found: Created Date is in Future"));
        break;
    case "CountryCodeLength":
        Assert.assertTrue(DriverConfig.getDriver().findElement(By.id("uploadError")).getText()
                .equalsIgnoreCase("Validator Errors found: Country Code Invalid"));
        break;
    case "InvalidEmailId":
        Assert.assertTrue(DriverConfig.getDriver().findElement(By.id("uploadError")).getText()
                .equalsIgnoreCase("Please fill in all required fields."));
        error = PageUtil.retrieveElementByTagText(DriverConfig.getDriver(), TAG_SPAN, "Invalid email address");
        Assert.assertTrue(error.getAttribute("htmlfor").equalsIgnoreCase("email"));
        break;
    case "InvalidProgramId":
        Assert.assertTrue(DriverConfig.getDriver().findElement(By.id("uploadError")).getText().trim()
                .equalsIgnoreCase("Invalid Program Id"));
        break;
    case "OtherLanguages":
        Assert.assertTrue(DriverConfig.getDriver().findElement(By.id("uploadError")).getText()
                .equalsIgnoreCase("Please fill in all required fields."));
        break;
    case "BlankMandatoryField":
        Assert.assertTrue(DriverConfig.getDriver().findElement(By.id("uploadError")).getText()
                .equalsIgnoreCase("Please fill in all required fields."));
        error = PageUtil.retrieveElementByTagText(DriverConfig.getDriver(), TAG_SPAN, "Enter Program Id");
        Assert.assertTrue(error.getAttribute("htmlfor").equalsIgnoreCase("programId"));
        break;
    case "CharachtersInProgramId":
        Assert.assertTrue(DriverConfig.getDriver().findElement(By.id("uploadError")).getText()
                .equalsIgnoreCase("Please fill in all required fields."));
        error = PageUtil.retrieveElementByTagText(DriverConfig.getDriver(), TAG_SPAN, "Enter Program Id");
        Assert.assertTrue(error.getAttribute("htmlfor").equalsIgnoreCase("programId"));
        break;
    case "CharachtersInPhoneNo":
        Assert.assertTrue(DriverConfig.getDriver().findElement(By.id("uploadError")).getText()
                .equalsIgnoreCase("Please fill in all required fields."));
        break;
    case "CharacthersInZipCode":
        Assert.assertTrue(DriverConfig.getDriver().findElement(By.id("uploadError")).getText()
                .equalsIgnoreCase("Please fill in all required fields."));
        break;
    case "NumbersInStateField":
        Assert.assertTrue(DriverConfig.getDriver().findElement(By.id("uploadError")).getText()
                .equalsIgnoreCase("Please fill in all required fields."));
        break;
    case "StateCodeLength":
        Assert.assertTrue(DriverConfig.getDriver().findElement(By.id("uploadError")).getText()
                .equalsIgnoreCase("Please fill in all required fields."));
        break;
    case "CharachtersInNoOfTSTATField":
        Assert.assertTrue(DriverConfig.getDriver().findElement(By.id("uploadError")).getText()
                .equalsIgnoreCase("Please fill in all required fields."));
        error = PageUtil.retrieveElementByTagText(DriverConfig.getDriver(), TAG_SPAN,
                "Enter Number of Thermostats");
        Assert.assertTrue(error.getAttribute("htmlfor").equalsIgnoreCase("numberOfThermostats"));
        break;
    case "CharachtersInAvgPrice":
        closeAlert(DriverConfig.getDriver());
        break;
    default:
        break;
    }

}

From source file:com.ecofactor.qa.automation.insite.page.UserManagementImpl.java

License:Open Source License

/**
 * Gets the account details.// w ww  .  j  a  va2 s  .  c o  m
 * @return the account details
 * @see com.ecofactor.qa.automation.insite.page.UserManagement#getAccountDetails()
 */
public Map<String, String> getAccountDetails() {

    DriverConfig.setLogString("Get account details.", true);
    final Map<String, String> accountDetailMap = new HashMap<String, String>();
    final WebElement firstNameElemt = DriverConfig.getDriver().findElement(By.id(userConfig.get(FIRST_NAME)));
    accountDetailMap.put(userConfig.get(FIRST_NAME), firstNameElemt.getAttribute(ATTR_VALUE));

    final WebElement lastNameElemt = DriverConfig.getDriver().findElement(By.id(userConfig.get(LAST_NAME)));
    accountDetailMap.put(userConfig.get(LAST_NAME), lastNameElemt.getAttribute(ATTR_VALUE));

    final WebElement emailElemt = DriverConfig.getDriver().findElement(By.id(userConfig.get(EMAIL_FIELD)));
    accountDetailMap.put(userConfig.get(EMAIL_FIELD), emailElemt.getAttribute(ATTR_VALUE));

    final Select selectElemt = new Select(
            DriverConfig.getDriver().findElement(By.id(userConfig.get(USER_STATUS))));
    accountDetailMap.put(userConfig.get(USER_STATUS), selectElemt.getFirstSelectedOption().getText());

    return accountDetailMap;
}

From source file:com.ecofactor.qa.automation.insite.page.UserManagementImpl.java

License:Open Source License

/**
 * Gets the contact details.// w  ww .  j a va2 s . com
 * @return the contact details
 * @see com.ecofactor.qa.automation.insite.page.UserManagement#getContactDetails()
 */
@Override
public Map<String, String> getContactDetails() {

    DriverConfig.setLogString("Get Contact details.", true);
    final Map<String, String> contactDetailMap = new HashMap<String, String>();
    final WebElement streetAddress1 = DriverConfig.getDriver()
            .findElement(By.id(userConfig.get(STREET_ADDRESS1)));
    contactDetailMap.put(userConfig.get(STREET_ADDRESS1), streetAddress1.getAttribute(ATTR_VALUE));
    final WebElement streetAddress2 = DriverConfig.getDriver()
            .findElement(By.id(userConfig.get(STREET_ADDRESS2)));
    contactDetailMap.put(userConfig.get(STREET_ADDRESS2), streetAddress2.getAttribute(ATTR_VALUE));
    final WebElement city = DriverConfig.getDriver().findElement(By.id(userConfig.get(CITY)));
    contactDetailMap.put(userConfig.get(CITY), city.getAttribute(ATTR_VALUE));
    final WebElement state = DriverConfig.getDriver().findElement(By.id(userConfig.get(STATE)));
    contactDetailMap.put(userConfig.get(STATE), state.getAttribute(ATTR_VALUE));
    final WebElement zip = DriverConfig.getDriver().findElement(By.id(userConfig.get(ZIP)));
    contactDetailMap.put(userConfig.get(ZIP), zip.getAttribute(ATTR_VALUE));
    final WebElement country = DriverConfig.getDriver().findElement(By.id(userConfig.get(COUNTRY)));
    contactDetailMap.put(userConfig.get(COUNTRY), country.getAttribute(ATTR_VALUE));
    final WebElement mobileNum = DriverConfig.getDriver().findElement(By.id(userConfig.get(MOBILE_NUM)));
    contactDetailMap.put(userConfig.get(MOBILE_NUM), mobileNum.getAttribute(ATTR_VALUE));
    final WebElement phoneNum = DriverConfig.getDriver().findElement(By.id(userConfig.get(PHONE_NUM)));
    contactDetailMap.put(userConfig.get(PHONE_NUM), phoneNum.getAttribute(ATTR_VALUE));
    final WebElement faxNum = DriverConfig.getDriver().findElement(By.id(userConfig.get(FAX_NUM)));
    contactDetailMap.put(userConfig.get(FAX_NUM), faxNum.getAttribute(ATTR_VALUE));
    return contactDetailMap;
}

From source file:com.ecofactor.qa.automation.insite.page.UserManagementImpl.java

License:Open Source License

/**
 * Gets the current page no./*from  w w w . ja  v a2 s  .c om*/
 * @return the current page no
 * @see com.ecofactor.qa.automation.insite.page.UserManagement#getCurrentPageNo()
 */
@Override
public int getCurrentPageNo() {

    WebElement element = DriverConfig.getDriver()
            .findElement(By.cssSelector("input.pagedisplay.ef_smallLabel.ieFix"));
    String pageNo = element.getAttribute(ATTR_VALUE).split(" ")[0];
    DriverConfig.setLogString("Current Page No : " + pageNo, true);
    return Integer.valueOf(pageNo);
}

From source file:com.ecofactor.qa.automation.insite.page.UserManagementImpl.java

License:Open Source License

/**
 * Gets the last page no./*from   w  w w  . j  a  va2 s  . co  m*/
 * @return the last page no
 * @see com.ecofactor.qa.automation.insite.page.UserManagement#getLastPageNo()
 */
@Override
public int getLastPageNo() {

    WebElement element = DriverConfig.getDriver()
            .findElement(By.cssSelector("input.pagedisplay.ef_smallLabel.ieFix"));
    String pageNo = element.getAttribute(ATTR_VALUE).split(" ")[0];
    DriverConfig.setLogString("Last Page No : " + pageNo, true);
    return Integer.valueOf(pageNo);
}

From source file:com.ecofactor.qa.automation.newapp.MobileTest.java

License:Open Source License

/**
 * Change set point by5.//from w w w  .  j  a  v  a 2 s .  c o m
 * @param picker the picker
 * @param increment the increment
 * @throws Exception the exception
 */
private void changeSetPointBy5(WebElement picker, boolean increment) throws Exception {

    int pickerOldValue = Integer.valueOf(picker.getAttribute("value"));
    for (int j = 1; j < 4; j++) {
        // int pickerValueToSet = increment ? pickerOldValue + j : pickerOldValue - j;
        WebElement pickerNewValue = mobileOps.getDeviceDriver()
                .findElement(By.xpath("//*[contains(@class,'dw-v')]/div[text()= '"
                        + (increment ? ++pickerOldValue : --pickerOldValue) + "']"));
        mobileUIAction.click(pickerNewValue);
    }
    WebElement pickerSetValue = mobileOps.getDeviceDriver()
            .findElement(By.xpath("//*[contains(@class,'dwbw')]/span[text()= 'Set']"));
    mobileUIAction.click(pickerSetValue);
    smallWait();
}

From source file:com.ecofactor.qa.automation.newapp.page.impl.AbstractSetAwayParameters.java

License:Open Source License

/**
 * Change value./*from  w  w w  .  j  a  v  a  2  s . co  m*/
 * @param value the value
 * @return the integer
 */
public Integer changeAwayParamValue(final SetAwayParams awayParams, final int value) {

    final int noOfSetPoints = Math.abs(value);

    WebElement containerElement = getElement(getDriver(), By.cssSelector("div.dwwl.dwwl0"), TINY_TIMEOUT);

    WebElement currentReadingElement = getElementBySubElement(getDriver(), containerElement,
            By.cssSelector(CURRENT_VALUE), TINY_TIMEOUT);
    String currentReadingValue = currentReadingElement.getAttribute(DATA_VALUE);

    final WebElement upOrDownArrow = value > 0
            ? getElementBySubElement(getDriver(), containerElement, By.cssSelector("a.dwb-e.dwwb.dwwbm"),
                    SHORT_TIMEOUT)
            : getElementBySubElement(getDriver(), containerElement, By.cssSelector("a.dwb-e.dwwb.dwwbp"),
                    SHORT_TIMEOUT);

    for (int count = 0; count < noOfSetPoints; count++) {
        getAction().click(upOrDownArrow);
    }

    currentReadingElement = getElementBySubElement(getDriver(), containerElement, By.cssSelector(CURRENT_VALUE),
            TINY_TIMEOUT);
    currentReadingValue = currentReadingElement.getAttribute(DATA_VALUE);

    saveAwaySettings();
    return Integer.parseInt(currentReadingValue);
}

From source file:com.ecofactor.qa.automation.newapp.page.impl.AwaySettingsOpsPageImpl.java

License:Open Source License

/**
 * Sets the away param picker./*from w ww .j  a v  a  2 s .  c  o  m*/
 * @param setAwayParams the set away params
 * @param expectedValue the expected value
 * @return true, if successful
 * @see com.ecofactor.qa.automation.newapp.page.AwaySettingsOpsPage#setAwayParam(com.ecofactor.qa.automation.newapp.enums.SetAwayParams,
 *      int)
 */
@Override
public boolean setAwayParamPicker(final SetAwayParams setAwayParams, final int expectedValue) {

    LogUtil.setLogString("Set " + setAwayParams + " as :" + expectedValue, true);

    final WebElement clickValue = getElement(getDriver(), By.cssSelector(".away_setting_picker"), TINY_TIMEOUT);
    WaitUtil.oneSec();
    getAction().click(clickValue);
    getAction().rejectAlert();

    final WebElement currentReadingElement = getElement(getDriver(), By.cssSelector(CURRENT_VALUE),
            TINY_TIMEOUT);

    final int currentReadingValue = Integer.parseInt(currentReadingElement.getAttribute(DATA_VALUE));

    final int setPointValue = currentReadingValue > expectedValue ? -(currentReadingValue - expectedValue)
            : expectedValue - currentReadingValue;

    return changeAwayParamValue(setAwayParams, setPointValue).equals(expectedValue);
}

From source file:com.ecofactor.qa.automation.newapp.page.impl.HelpOverlayPageImpl.java

License:Open Source License

/**
 * @param page//ww  w .ja  va  2 s. c o m
 * @see com.ecofactor.qa.automation.newapp.page.HelpOverlayPage#isSlideLoaded(com.ecofactor.qa.automation.newapp.enums.HelpPage)
 */
@Override
public boolean isSlideLoaded(final HelpPage page, final String image) {

    Object bimage = null;
    final WebElement targetElement = getElement(getDriver(), By.cssSelector("div.help_slide_img"),
            TINY_TIMEOUT);
    bimage = targetElement.getAttribute("style");
    return bimage.toString().contains(image);
}

From source file:com.ecofactor.qa.automation.newapp.page.impl.LocationSwitcherUIPageImpl.java

License:Open Source License

/**
 * Gets the tstat namesin location./*from  ww  w . jav  a  2s  . c  o m*/
 * @param locId the loc id
 * @return the tstat namesin location
 * @see com.ecofactor.qa.automation.newapp.page.LocationSwitcherUIPage#getTstatNamesinLocation(Integer)
 */
@Override
public List<String> getTstatNamesinLocation(final Integer locId) {

    LogUtil.setLogString("Get Thermostat Names for location id :" + locId, true, CustomLogLevel.LOW);
    final WebElement thermostatSwitcherContainer = getElement(getDriver(),
            By.className(THERMOSTAT_SWITCHER_CONTAINER), SHORT_TIMEOUT);
    final List<WebElement> tstatName = getElementsBySubElement(getDriver(), thermostatSwitcherContainer,
            By.cssSelector(THERMOSTAT_ROW), SHORT_TIMEOUT);
    final List<String> tstatNames = new ArrayList<String>();
    for (final WebElement element1 : tstatName) {
        final String locId1 = element1.getAttribute(LOCATION_ID);
        if (locId1.equalsIgnoreCase(String.valueOf(locId))) {
            final WebElement tstatName1 = getElementBySubElement(getDriver(), element1,
                    By.className(THERMOSTAT_NAME), SHORT_TIMEOUT);
            tstatNames.add(tstatName1.getText());
        }
    }
    return tstatNames;
}