Example usage for org.openqa.selenium WebElement isSelected

List of usage examples for org.openqa.selenium WebElement isSelected

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement isSelected.

Prototype

boolean isSelected();

Source Link

Document

Determine whether or not this element is selected or not.

Usage

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

License:Apache License

public String getSelectedText() {
    findElement();//from  www .  jav  a  2  s  .com
    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();/*from   w ww  .j  av  a  2  s . c o m*/

    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);
}

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

License:Apache License

public String getSelectedValue() {
    findElement();/*from   w w  w. java 2  s  . com*/
    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();//  w  ww  .ja v 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

private void setSelected(final WebElement option) {
    if (!option.isSelected()) {
        option.click();
    }
}

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.francetelecom.clara.cloud.webapp.acceptancetest.utils.SeleniumUtils.java

License:Apache License

public static WebElement waitForElementSelected(WebElement webElement, long timeout) {
    long start = System.currentTimeMillis();
    if (null == webElement) {
        return webElement;
    }/*from w w  w .  j  a  v a2s . co m*/
    while (!webElement.isSelected()) {
        Assert.assertTrue("Timeout (>" + timeout + "ms) while waiting for web element " + webElement.toString()
                + " to be selected", System.currentTimeMillis() - start < timeout);
        waitForASecond();
    }
    return webElement;
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput2Test.java

License:Apache License

/**
 * @throws Exception if an error occurs//from   ww  w .  jav a2  s.  c  o m
 */
@Test
public void preventDefault() throws Exception {
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><script>\n"
            + "  function handler(e) {\n" + "    if (e)\n" + "      e.preventDefault();\n" + "    else\n"
            + "      return false;\n" + "  }\n" + "  function init() {\n"
            + "    document.getElementById('checkbox1').onclick = handler;\n" + "  }\n" + "</script></head>\n"
            + "<body onload='init()'>\n" + "<input type='checkbox' id='checkbox1'/>\n" + "</body></html>";

    final WebDriver driver = loadPage2(html);
    final WebElement checkbox = driver.findElement(By.id("checkbox1"));
    checkbox.click();
    assertFalse(checkbox.isSelected());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput2Test.java

License:Apache License

/**
 * Verifies that a HtmlCheckBox is unchecked by default.
 * The onClick tests make this assumption.
 * @throws Exception if the test fails/*from ww w. j  a v  a 2  s.c  om*/
 */
@Test
public void defaultState() throws Exception {
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>foo</title></head><body>\n"
            + "<form id='form1'>\n"
            + "  <input type='checkbox' name='checkbox' id='checkbox'>Check me</input>\n"
            + "</form></body></html>";
    final WebDriver driver = loadPage2(html);
    final WebElement checkbox = driver.findElement(By.id("checkbox"));
    assertFalse(checkbox.isSelected());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput2Test.java

License:Apache License

/**
 * @throws Exception if an error occurs/*w  ww .  jav a 2 s . c o m*/
 */
@Test
public void preventDefault() throws Exception {
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><script>\n"
            + "  function handler(e) {\n" + "    if (e)\n" + "      e.preventDefault();\n" + "    else\n"
            + "      return false;\n" + "  }\n" + "  function init() {\n"
            + "    document.getElementById('radio1').onclick = handler;\n" + "  }\n" + "</script></head>\n"
            + "<body onload='init()'>\n" + "  <input type='radio' id='radio1' name='radio1' />\n"
            + "</body></html>";

    final WebDriver driver = loadPage2(html);
    final WebElement radio = driver.findElement(By.id("radio1"));
    radio.click();
    assertFalse(radio.isSelected());
}