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.mgmtp.jfunk.web.util.WebDriverTool.java

License:Apache License

/**
 * Delegates to {@link #findElement(By)} and then calls
 * {@link WebElement#getAttribute(String) getAttribute(String)} on the returned element.
 *
 * @param by/*w ww . j  a v a 2  s  . com*/
 *            the {@link By} used to locate the element
 * @param attributeName
 *            the attribute name
 * @return the attribute value
 */
public String getAttributeValue(final By by, final String attributeName) {
    WebElement element = findElement(by);
    return element.getAttribute(attributeName);
}

From source file:com.mgmtp.jfunk.web.util.WebDriverTool.java

License:Apache License

/**
 * <p>/*ww w .  j a  v a 2  s .  c  o  m*/
 * Delegates to {@link #findElement(By)} and then calls
 * {@link WebElement#getAttribute(String) getAttribute("innerText")} on the returned
 * element. If {@code normalizeSpace} is {@code true} , the element's text is passed to
 * {@link JFunkUtils#normalizeSpace(String)}.
 * </p>
 * <p>
 * The difference to {@link #getElementText(By, boolean)} is that this method returns the
 * complete inner text of the element, not only the visible (i. e. not hidden by CSS) one.
 * </p>
 *
 * @param by
 *            the {@link By} used to locate the element
 * @param normalizeSpace
 *            specifies whether whitespace in the element text are to be normalized
 * @return the text
 */
public String getInnerText(final By by, final boolean normalizeSpace) {
    WebElement element = findElement(by);
    String text = element.getAttribute("innerText");
    return normalizeSpace ? JFunkUtils.normalizeSpace(text) : text;
}

From source file:com.mgmtp.jfunk.web.util.WebDriverTool.java

License:Apache License

private String outerHtmlPreview(WebElement webElement) {
    String outerHtml = webElement.getAttribute("outerHTML");
    int maxPreviewLength = 256;
    if (outerHtml.length() > maxPreviewLength) {
        outerHtml = outerHtml.substring(0, maxPreviewLength) + "...";
    }/* ww  w .j  ava2 s.  com*/
    return outerHtml;
}

From source file:com.mkl.websuites.internal.command.impl.check.CheckCheckboxCommand.java

License:Apache License

@Override
protected void doOperationOnElement(WebElement elem) {

    if (!(elem.getTagName().equalsIgnoreCase("input")
            && elem.getAttribute("type").equalsIgnoreCase("checkbox"))) {
        fail("Element expected to be a checkbox");
    }//from  www.  j a  v a2s  . c o  m

    actualCheckedValue = elem.getAttribute(checkedAttributeValue);

    actualCheckedValue = actualCheckedValue == null ? "false" : actualCheckedValue;

    AbstractCheck checkLogic = defineCheckLogic();

    checkLogic.runStandardCommand();

}

From source file:com.mkl.websuites.internal.command.impl.check.CheckCssClassCommand.java

License:Apache License

@Override
protected void doOperationOnElement(WebElement elem) {

    expectedCssClassName = parameterMap.get(CSS_CLASS_ATTR);

    actualCssClassNames = elem.getAttribute("class");

    AbstractCheck checkLogic = defineCheckLogic();

    checkLogic.runStandardCommand();//www  .  jav  a2  s .  co  m
}

From source file:com.mkl.websuites.internal.command.impl.check.CheckElementAttributeCommand.java

License:Apache License

@Override
protected void doOperationOnElement(WebElement elem) {

    inputAttributeName = parameterMap.get(ATT_NAME_PARAM);
    actualAttributeValue = elem.getAttribute(inputAttributeName);

    AbstractCheck checkLogic = defineCheckLogic();

    checkLogic.runStandardCommand();//from  w  w  w . j  av a2s  . c  o m

}

From source file:com.mkl.websuites.internal.command.impl.check.CheckElementInnerHtmlCommand.java

License:Apache License

@Override
protected void doOperationOnElement(WebElement elem) {

    actualInnerHtml = elem.getAttribute(INNER_HTML_PARAM);

    // not all browsers may support innerHTML attribute on WebElement level, so
    // use Javascript invocation then instead:
    if (actualInnerHtml == null) {

        actualInnerHtml = (String) ((JavascriptExecutor) browser)
                .executeScript("return arguments[0].innerHTML;", elem);
    }//from  ww w .j a  va 2  s .co  m

    AbstractCheck checkLogic = defineCheckLogic();

    expectedInnerHtml = parameterMap.get(INNER_HTML_PARAM);

    checkLogic.runStandardCommand();

}

From source file:com.mkl.websuites.internal.command.impl.check.CheckHeaderContainsCommand.java

License:Apache License

@Override
protected String getStringParam() {
    WebElement headElem;
    try {//ww w  .j a  v  a 2  s. com
        headElem = browser.findElement(By.tagName("head"));
        return headElem.getAttribute("innerHTML");
    } catch (NoSuchElementException e) {
        return "";
    }
}

From source file:com.mkl.websuites.internal.command.impl.check.CheckLinkHrefCommand.java

License:Apache License

@Override
protected String getStringParam() {

    try {/*from  w  w w .  ja  va2 s. co m*/
        List<WebElement> elements = browser.findElements(By.tagName("a"));
        for (WebElement elem : elements) {
            if (predicate(elem.getAttribute("href"))) {
                actualElement = elem;
                return "OK";
            }
        }
    } catch (NoSuchElementException e) {
        return null;
    }
    return null;
}

From source file:com.mkl.websuites.internal.command.impl.CommandUtils.java

License:Apache License

public static boolean checkIfElementIsCheckBox(WebElement element) {
    String checkedAtt = element.getAttribute("type");
    return element.getTagName().equalsIgnoreCase("input") && checkedAtt != null
            && checkedAtt.equals("checkbox");
}