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.util.PageUtil.java

License:Open Source License

/**
 * <b> verify the particular value is displayed according to the attribute</b>.
 * @param driver the driver//from   w  w  w  .  j  av  a 2 s  .c o  m
 * @param tagName the tag name
 * @param attributeName the attribute name
 * @param attributeValue the attribute value
 * @return the list
 */
public static List<WebElement> retrieveElementsByAttributeValueList(final WebDriver driver,
        final String tagName, final String attributeName, final String attributeValue) {

    List<WebElement> elementList = driver.findElements(By.tagName(tagName));
    List<WebElement> listElement = new ArrayList<WebElement>();

    for (WebElement webElement : elementList) {
        String valueAttribute = webElement.getAttribute(attributeName.trim());
        if (valueAttribute.trim().equalsIgnoreCase(attributeValue))
            listElement.add(webElement);
    }

    return listElement;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Retrieve element by contains of attribute value.
 * @param driver the driver//from   w  w  w. j  a v  a 2 s  .  c  o m
 * @param tagName the tag name
 * @param attributeName the attribute name
 * @param attributeValue the attribute value
 * @param timeOut the time out
 * @return the web element
 */
public static WebElement retrieveElementByContainsOfAttributeValue(final WebDriver driver, final String tagName,
        final String attributeName, final String attributeValue, final int timeOut) {

    elementContainsAttrValue = null;
    (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver d) {

            boolean isLoaded = false;
            List<WebElement> elementList = driver.findElements(By.tagName(tagName));
            for (WebElement webElement : elementList) {
                String valueAttribute = webElement.getAttribute(attributeName.trim());
                if (valueAttribute != null && valueAttribute.trim().contains(attributeValue)) {
                    elementContainsAttrValue = webElement;
                    isLoaded = true;
                    break;
                }
            }
            return isLoaded;
        }
    });

    return elementContainsAttrValue;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Retrieve elements by contains of attribute value.
 * @param driver the driver/*  w w  w .j  a v  a 2s  .c o m*/
 * @param tagName the tag name
 * @param attributeName the attribute name
 * @param attributeValue the attribute value
 * @return the list
 */
public static List<WebElement> retrieveElementsByContainsOfAttributeValue(final WebDriver driver,
        final String tagName, final String attributeName, final String attributeValue) {

    List<WebElement> elementListGroup = new ArrayList<WebElement>();
    List<WebElement> elementList = driver.findElements(By.tagName(tagName));
    for (WebElement webElement : elementList) {
        String valueAttribute = webElement.getAttribute(attributeName.trim());
        if (valueAttribute != null && valueAttribute.trim().contains(attributeValue)) {
            elementContainsAttrValue = webElement;
            elementListGroup.add(webElement);
        }
    }

    return elementListGroup;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Retrieve element by attribute value for sub element.
 * @param driver the driver/*from w ww .  j a v a 2s . c  o m*/
 * @param subElement the sub element
 * @param tagName the tag name
 * @param attributeName the attribute name
 * @param attributeValue the attribute value
 * @param timeOut the time out
 * @return the web element
 */
public static WebElement retrieveElementByAttributeValueForSubElement(final WebDriver driver,
        final WebElement subElement, final String tagName, final String attributeName,
        final String attributeValue, final int timeOut) {

    subElementEqualsAttrValue = null;
    (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver d) {

            boolean isLoaded = false;
            List<WebElement> elementList = subElement.findElements(By.tagName(tagName));
            for (WebElement webElement : elementList) {
                String valueAttribute = webElement.getAttribute(attributeName.trim());
                if (valueAttribute.trim().equalsIgnoreCase(attributeValue)) {
                    subElementEqualsAttrValue = webElement;
                    isLoaded = true;
                    break;
                }
            }
            return isLoaded;
        }
    });

    return subElementEqualsAttrValue;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Retrieve element by attribute value contains for sub element.
 * @param driver the driver/*from w w  w.  j a  v a  2s.com*/
 * @param subElement the sub element
 * @param tagName the tag name
 * @param attributeName the attribute name
 * @param attributeValue the attribute value
 * @param timeOut the time out
 * @return the web element
 */
public static WebElement retrieveElementByAttributeValueContainsForSubElement(final WebDriver driver,
        final WebElement subElement, final String tagName, final String attributeName,
        final String attributeValue, final int timeOut) {

    subElementContainsAttrValue = null;
    try {
        (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() {

            public Boolean apply(WebDriver d) {

                boolean isLoaded = false;
                List<WebElement> elementList = subElement.findElements(By.tagName(tagName));
                for (WebElement webElement : elementList) {
                    String valueAttribute = webElement.getAttribute(attributeName.trim());
                    if (valueAttribute.trim().contains(attributeValue)) {
                        subElementContainsAttrValue = webElement;
                        isLoaded = true;
                        break;
                    }
                }
                return isLoaded;
            }
        });
    } catch (TimeoutException te) {

    }

    return subElementContainsAttrValue;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * <b> verify the particular value is displayed according to the attribute</b>.
 * @param driver the driver//  ww w . jav  a2  s. c  om
 * @param rootElement the root element
 * @param tagName the tag name
 * @param attributeName the attribute name
 * @param attributeValue the attribute value
 * @return the web element
 */
public static WebElement retrieveElementByAttributeValueByPassingElement(final WebDriver driver,
        final WebElement rootElement, final String tagName, final String attributeName,
        final String attributeValue) {

    WebElement element = null;
    List<WebElement> elementList = rootElement.findElements(By.tagName(tagName));
    for (WebElement webElement : elementList) {
        String valueAttribute = webElement.getAttribute(attributeName.trim());
        if (valueAttribute.trim().equalsIgnoreCase(attributeValue)) {
            return webElement;
        }
    }

    return element;
}

From source file:com.elastica.webelements.SelectList.java

License:Apache License

public void deselectByText(final String text) {
    TestLogging.logWebStep(null, "deselect text\"" + text + "\" on " + toHTML(), false);
    findElement();//from   www .ja v  a 2 s.c o  m
    for (WebElement option : options) {
        if (option.getAttribute("text").equals(text)) {
            if (option.isSelected()) {
                option.click();
            }

            break;
        }
    }
}

From source file:com.elastica.webelements.SelectList.java

License:Apache License

public void deselectByValue(final String value) {
    TestLogging.logWebStep(null, "deselect value\"" + value + "\" on " + toHTML(), false);
    findElement();/*w ww  .  j av  a  2  s . c  o m*/
    for (WebElement option : options) {
        if (option.getAttribute("value").equals(value)) {
            if (option.isSelected()) {
                option.click();
            }

            break;
        }
    }

}

From source file:com.elastica.webelements.SelectList.java

License:Apache License

public String getSelectedText() {
    findElement();/*w w w  .j ava 2 s. c  om*/
    for (WebElement option : options) {
        if (option.isSelected()) {
            return option.getAttribute("text");
        }
    }

    return null;
}

From source file:com.elastica.webelements.SelectList.java

License:Apache License

public String[] getSelectedTexts() {
    findElement();//ww w. ja  va 2 s  . c  om

    List<String> textList = new ArrayList<String>();
    for (WebElement option : options) {
        if (option.isSelected()) {
            textList.add(option.getAttribute("text"));
        }
    }

    String[] texts = new String[textList.size()];
    return textList.toArray(texts);
}