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:org.mule.modules.selenium.SeleniumModule.java

License:Open Source License

/**
 * Determine whether or not this element is selected or not. This operation only applies to input
 * elements such as checkboxes, options in a select and radio buttons.
 * <p/>//from  ww  w  . j  a  v  a 2  s.c o m
 * {@sample.xml ../../../doc/mule-module-selenium.xml.sample selenium:is-selected}
 *
 * @param element Element located at the payload of the message
 * @return True if the element is currently selected or checked, false otherwise.
 */
@Processor
public boolean isSelected(@Payload WebElement element) {
    return element.isSelected();
}

From source file:org.musetest.selenium.conditions.ElementSelectedCondition.java

License:Open Source License

@Override
public Boolean resolveValue(MuseExecutionContext context) throws ValueSourceResolutionError {
    WebElement element = resolveElementSource(context, true);
    boolean visible = element.isSelected();
    context.raiseEvent(ValueSourceResolvedEventType.create(getDescription(), visible));
    return visible;
}

From source file:org.nuxeo.functionaltests.contentView.ContentViewElement.java

License:Apache License

/**
 * @since 9.1/*www  .  ja v  a 2 s  . c o  m*/
 */
public ContentViewSelectionActions selectByTitle(String... titles) {
    // get id before element is detached from DOM (during next ajax calls)
    String id = getId();
    List<WebElement> items = getItems();
    for (WebElement item : items) {
        for (String title : titles) {
            try {
                item.findElement(By.linkText(title));
                AjaxRequestManager arm = new AjaxRequestManager(driver);
                arm.begin();
                WebElement element = item.findElement(By.xpath(CHECK_BOX_XPATH));
                assertFalse("Element with title=" + title + " is already selected", element.isSelected());
                Locator.scrollAndForceClick(element);
                arm.end();
                break;
            } catch (NoSuchElementException e) {
                // next
            }
        }
    }
    return reload(id).getSelectionActions();
}

From source file:org.nuxeo.functionaltests.contentView.ContentViewElement.java

License:Apache License

/**
 * @since 9.1/*  w w  w  .ja v a2 s  .  c om*/
 */
public ContentViewElement unselectByTitle(String... titles) {
    // get id before element is detached from DOM (during next ajax calls)
    String id = getId();
    List<WebElement> items = getItems();
    for (WebElement item : items) {
        for (String title : titles) {
            try {
                item.findElement(By.linkText(title));
                AjaxRequestManager arm = new AjaxRequestManager(driver);
                arm.begin();
                WebElement element = item.findElement(By.xpath(CHECK_BOX_XPATH));
                assertTrue("Element with title=" + title + " is not selected", element.isSelected());
                Locator.scrollAndForceClick(element);
                arm.end();
                break;
            } catch (NoSuchElementException e) {
                // next
            }
        }
    }
    return reload(id);
}

From source file:org.nuxeo.functionaltests.contentView.ContentViewElement.java

License:Apache License

/**
 * @since 9.1/*from ww  w  . j a v a 2 s  . c  om*/
 */
public ContentViewSelectionActions selectByIndex(int... indexes) {
    // get id before element is detached from DOM (during next ajax calls)
    String id = getId();
    AjaxRequestManager arm = new AjaxRequestManager(driver);
    for (int i : indexes) {
        arm.watchAjaxRequests();
        WebElement element = getItems().get(i).findElement(By.xpath(CHECK_BOX_XPATH));
        assertFalse("Element with id=" + i + " is already selected", element.isSelected());
        Locator.scrollAndForceClick(element);
        arm.waitForAjaxRequests();
    }
    return reload(id).getSelectionActions();
}

From source file:org.nuxeo.functionaltests.contentView.ContentViewElement.java

License:Apache License

/**
 * @since 9.1// www  .ja v  a 2s .c  o m
 */
public ContentViewElement unselectByIndex(int... indexes) {
    // get id before element is detached from DOM (during next ajax calls)
    String id = getId();
    AjaxRequestManager arm = new AjaxRequestManager(driver);
    for (int i : indexes) {
        arm.watchAjaxRequests();
        WebElement element = getItems().get(i).findElement(By.xpath(CHECK_BOX_XPATH));
        assertTrue("Element with id=" + i + " is not selected", element.isSelected());
        Locator.scrollAndForceClick(element);
        arm.waitForAjaxRequests();
    }
    return reload(id);
}

From source file:org.nuxeo.functionaltests.contentView.ContentViewElement.java

License:Apache License

/**
 * @since 9.1/*from  w  w w.ja  va2  s.  co  m*/
 */
public ContentViewSelectionActions selectAll() {
    WebElement selectAll = getResultsPanel().findElement(By.xpath(SELECT_ALL_BUTTON_XPATH));
    assertFalse("Select all Element is already selected", selectAll.isSelected());
    // get id before element is detached from DOM (during next ajax call)
    String id = getId();
    AjaxRequestManager arm = new AjaxRequestManager(driver);
    arm.begin();
    Locator.scrollAndForceClick(selectAll);
    arm.end();
    return reload(id).getSelectionActions();
}

From source file:org.nuxeo.functionaltests.contentView.ContentViewElement.java

License:Apache License

/**
 * CAUTION You can call this method only after a {@link #selectAll()}.
 * /*from  ww w. j a va2  s.  c om*/
 * @since 9.1
 */
public ContentViewElement unselectAll() {
    WebElement selectAll = getResultsPanel().findElement(By.xpath(SELECT_ALL_BUTTON_XPATH));
    assertTrue("Select all Element is not selected", selectAll.isSelected());
    // get id before element is detached from DOM (during next ajax call)
    String id = getId();
    AjaxRequestManager arm = new AjaxRequestManager(driver);
    arm.begin();
    Locator.scrollAndForceClick(selectAll);
    arm.end();
    return reload(id);
}

From source file:org.nuxeo.functionaltests.forms.SelectManyCheckboxDirectoryWidgetElement.java

License:Apache License

@Override
public void setInput(WebElement elt, String value) {
    List<WebElement> options = getInputElement().findElements(By.xpath(".//input[@type='checkbox']"));
    List<String> ids = new ArrayList<String>();
    if (StringUtils.isBlank(value)) {
        for (WebElement option : options) {
            if (option.isSelected()) {
                ids.add(option.getAttribute("id"));
            }//from w w w.j  a va  2  s  .  co m
        }
    } else {
        String[] split = value.split(",");
        for (String v : split) {
            for (WebElement option : options) {
                if (option.getAttribute("value").equals(v) && !option.isSelected()) {
                    ids.add(option.getAttribute("id"));
                }
            }
        }
    }
    // click options by id in case widget is ajaxified
    for (String id : ids) {
        driver.findElement(By.id(id)).click();
    }
}

From source file:org.nuxeo.functionaltests.forms.SelectManyCheckboxDirectoryWidgetElement.java

License:Apache License

@Override
public String getInputValue() {
    StringBuilder res = new StringBuilder();
    List<WebElement> options = getInputElement().findElements(By.xpath(".//input[type='checkbox']"));
    for (WebElement option : options) {
        if (option.isSelected()) {
            if (res.length() != 0) {
                res.append(",");
            }/*w  w  w . j a v  a2  s.  c o m*/
            res.append(option.getAttribute("value"));
        }
    }
    return res.toString();
}