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.elastica.webelements.SelectList.java

License:Apache License

public String getSelectedValue() {
    findElement();/*from   ww w  . j a  va  2s . c o m*/
    for (WebElement option : options) {
        if (option.isSelected()) {
            return option.getAttribute("value");
        }
    }

    return null;
}

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

License:Apache License

public String[] getSelectedValues() {
    findElement();//  ww  w  .jav a  2  s. co m

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

    String[] values = new String[valueList.size()];
    return valueList.toArray(values);
}

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

License:Apache License

/**
 * Select standard select by attribute text, and select fake select with ul and li by attribute title.
 *
 * @param  text//from  ww  w .j a v a 2  s . c  om
 */
public void selectByText(final String text) {
    TestLogging.logWebStep(null, "make selection using text\"" + text + "\" on " + toHTML(), false);
    findElement();
    if (options == null) {
        driver.findElement(By.xpath("//li[text()='" + text + "']")).click();
        return;
    }

    for (WebElement option : options) {
        String selectedText = null;
        if (option.getTagName().equalsIgnoreCase("li")) {
            selectedText = option.getAttribute("title");
        } else {
            selectedText = option.getAttribute("text");
        }

        if (selectedText.equals(text)) {
            setSelected(option);
            break;
        }
    }
}

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

License:Apache License

public void selectByText(final String[] texts) {
    TestLogging.logWebStep(null, "make selection using texts\"" + texts + "\" on " + toHTML(), false);
    findElement();/*ww  w .j  ava  2s. c o  m*/
    for (int i = 0; i < texts.length; i++) {
        for (WebElement option : options) {
            if (option.getAttribute("text").equals(texts[i])) {
                setSelected(option);
                break;
            }
        }
    }
}

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

License:Apache License

public void selectByValue(final String value) {
    TestLogging.logWebStep(null, "make selection using value\"" + value + "\" on " + toHTML(), false);
    findElement();//from   w  w  w.j a v  a  2  s .  co m
    for (WebElement option : options) {
        if (option.getAttribute("value").equals(value)) {
            setSelected(option);
            break;
        }
    }
}

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

License:Apache License

public void selectByValue(final String[] values) {
    TestLogging.logWebStep(null, "make selection using values\"" + values + "\" on " + toHTML(), false);
    findElement();/* w w w  .j  a v  a  2  s  .c  o m*/
    for (int i = 0; i < values.length; i++) {
        for (WebElement option : options) {
            if (option.getAttribute("value").equals(values[i])) {
                setSelected(option);
                break;
            }
        }
    }
}

From source file:com.epam.jdi.uitests.mobile.appium.elements.complex.BaseSelector.java

License:Open Source License

protected boolean isSelectedAction(WebElement el) {
    if (isSelector)
        return el.isSelected();
    String attr = el.getAttribute("checked");
    return attr != null && attr.equals("true");
}

From source file:com.epam.jdi.uitests.web.selenium.driver.SeleniumDriverFactory.java

License:Open Source License

public void highlight(IElement element, HighlightSettings settings) {
    HighlightSettings highlightSettings = settings;
    if (highlightSettings == null)
        highlightSettings = new HighlightSettings();
    WebElement webElement = ((Element) element).getHighLightElement();
    String orig = webElement.getAttribute("style");
    getJSExecutor().executeScript(format("arguments[0].setAttribute('%s',arguments[1]);", "style"), webElement,
            format("border: 3px solid %s; background-color: %s;", highlightSettings.getFrameColor(),
                    highlightSettings.getBgColor()));
    sleep(highlightSettings.getTimeoutInSec() * 1000);
    getJSExecutor().executeScript(format("arguments[0].setAttribute('%s',arguments[1]);", "style"), webElement,
            orig);//from  w  w  w . j a  va2  s.  c o m
}

From source file:com.epam.jdi.uitests.web.selenium.elements.common.Text.java

License:Open Source License

protected String getTextAction() {
    WebElement element = getWebElement();
    String getValue = element.getAttribute("value");
    if (getValue != null && !getValue.equals(""))
        return getValue;
    String getText = element.getText();
    return getText != null ? getText : getValue;
}

From source file:com.example.getstarted.basicactions.UserJourneyTestIT.java

License:Apache License

private void checkAddBookPage() throws Exception {
    List<WebElement> inputContainers = driver.findElements(By.cssSelector("form .form-group"));
    assertTrue("Should have more than 5 inputs", inputContainers.size() > 5);
    assertEquals("First input should be Title", "Title",
            inputContainers.get(0).findElement(By.tagName("label")).getText());
    assertEquals("Second input should be Author", "Author",
            inputContainers.get(1).findElement(By.tagName("label")).getText());
    assertEquals("Third input should be Date Published", "Date Published",
            inputContainers.get(2).findElement(By.tagName("label")).getText());
    assertEquals("Fourth input should be Description", "Description",
            inputContainers.get(3).findElement(By.tagName("label")).getText());

    // The rest should be hidden
    for (Iterator<WebElement> iter = inputContainers.listIterator(5); iter.hasNext();) {
        WebElement el = iter.next();
        assertTrue(el.getAttribute("class").indexOf("hidden") >= 0);
    }/*from  w  w w  . j  av  a2  s. co  m*/
}