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.thoughtworks.selenium.webdriven.commands.RemoveAllSelections.java

License:Apache License

private void removeAllSelections(List<WebElement> options) {
    for (WebElement option : options) {
        if (option.isSelected())
            option.click();/*from   ww  w.  j a v  a2s  .  c o m*/
    }
}

From source file:com.thoughtworks.selenium.webdriven.commands.SeleniumSelect.java

License:Apache License

public void setSelected(String optionLocator) {
    if (isMultiple()) {
        for (WebElement opt : select.findElements(By.tagName("option"))) {
            if (opt.isSelected()) {
                opt.click();//ww  w.j  a  v  a 2 s .c  om
            }
        }
    }

    WebElement option = findOption(optionLocator);
    if (!option.isSelected()) {
        option.click();
    }
}

From source file:com.thoughtworks.selenium.webdriven.commands.SeleniumSelect.java

License:Apache License

public void addSelection(String optionLocator) {
    assertSupportsMultipleSelections();//from   w  w w  .j a  va 2 s . c o m

    WebElement option = findOption(optionLocator);
    if (!option.isSelected()) {
        option.click();
    }
}

From source file:com.thoughtworks.selenium.webdriven.commands.SeleniumSelect.java

License:Apache License

public void removeSelection(String optionLocator) {
    assertSupportsMultipleSelections();//  www .  j a va  2 s  .  c o  m

    WebElement option = findOption(optionLocator);
    if (option.isSelected()) {
        option.click();
    }
}

From source file:com.thoughtworks.selenium.webdriven.commands.SeleniumSelect.java

License:Apache License

public List<WebElement> getSelectedOptions() {
    List<WebElement> toReturn = Lists.newArrayList();

    for (WebElement option : select.findElements(By.tagName("option"))) {
        if (option.isSelected()) {
            toReturn.add(option);/*from ww w . j a v a2  s .c o  m*/
        }
    }

    return toReturn;
}

From source file:com.thoughtworks.selenium.webdriven.commands.Uncheck.java

License:Apache License

@Override
protected Void handleSeleneseCommand(WebDriver driver, String locator, String value) {
    alertOverride.replaceAlertMethod(driver);

    WebElement element = finder.findElement(driver, locator);
    if (element.isSelected())
        element.click();/* ww  w.  j  av a  2  s.com*/

    return null;
}

From source file:com.thoughtworks.webanalyticsautomation.scriptrunner.WebDriverScriptRunner.java

License:Open Source License

public String getHTMLSourceByExecutingScript(final String OMNITURE_DEBUGGER_URL,
        String OMNITURE_DEBUGGER_WINDOW_TITLE, String OMNITURE_DEBUGGER_URL_DECODE_CHECKBOX) {
    String htmlSource = null;/* w  w w.j  a  v  a 2s. c om*/
    String parentWindowHandle = webDriverInstance.getWindowHandle();
    logger.debug("parentWindowHandle = " + parentWindowHandle);
    logger.info("Opening Omniture Debugger: " + OMNITURE_DEBUGGER_URL);
    ((JavascriptExecutor) webDriverInstance).executeScript(OMNITURE_DEBUGGER_URL);
    try {
        boolean windowFound = false;
        while (!windowFound) {
            Set<String> windowHandles = webDriverInstance.getWindowHandles();
            for (String windowHandle : windowHandles) {
                logger.debug("windowHandle = " + windowHandle);
                if (!windowHandle.equalsIgnoreCase(parentWindowHandle)) {
                    webDriverInstance = webDriverInstance.switchTo().window(windowHandle);
                    WebElement element = webDriverInstance
                            .findElement(By.name(OMNITURE_DEBUGGER_URL_DECODE_CHECKBOX));
                    if (!element.isSelected()) {
                        logger.debug("checkbox not selected. clicking on it.");
                        element.click();
                        while (!element.isSelected()) {
                            logger.debug("checkbox status: " + element.isSelected());
                            Thread.sleep(3000);
                        }
                    }
                    Thread.sleep(3000);
                    htmlSource = webDriverInstance.getPageSource();
                    webDriverInstance.close();//child window closing
                    windowFound = true;
                    break;
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    webDriverInstance.switchTo().window(parentWindowHandle);
    webDriverInstance.close();
    logger.debug("WebDriver omniture debugger page source: \n" + htmlSource);
    return htmlSource;
}

From source file:com.uisteps.core.user.browser.pages.elements.radio.RadioButtonGroup.java

License:Apache License

public RadioButton getSelectedButton() {

    for (WebElement button : wrappedRadio.getButtons()) {
        if (button.isSelected()) {
            return new RadioButton(button, browser);
        }/*  w  ww . j  av a2  s .com*/
    }
    return null;
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridSelectionTest.java

License:Apache License

@Test
public void testServerSideSelectTogglesSelectAllCheckBox() {
    openTestURL();/*from w w w .  ja v a 2s .  c om*/

    setSelectionModelMulti();
    GridCellElement header = getGridElement().getHeaderCell(0, 0);

    WebElement selectAll = header.findElement(By.tagName("input"));

    selectMenuPath("Component", "State", "Select all");
    waitUntilCheckBoxValue(selectAll, true);
    assertTrue("Select all CheckBox wasn't selected as expected", selectAll.isSelected());

    selectMenuPath("Component", "State", "Select none");
    waitUntilCheckBoxValue(selectAll, false);
    assertFalse("Select all CheckBox was selected unexpectedly", selectAll.isSelected());

    selectMenuPath("Component", "State", "Select all");
    waitUntilCheckBoxValue(selectAll, true);
    getGridElement().getCell(5, 0).click();
    waitUntilCheckBoxValue(selectAll, false);
    assertFalse("Select all CheckBox was selected unexpectedly", selectAll.isSelected());
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridSelectionTest.java

License:Apache License

private void waitUntilCheckBoxValue(final WebElement checkBoxElememnt, final boolean expectedValue) {
    waitUntil(new ExpectedCondition<Boolean>() {
        @Override/*from w  w w  .  j  a va  2s .  co  m*/
        public Boolean apply(WebDriver input) {
            return expectedValue ? checkBoxElememnt.isSelected() : !checkBoxElememnt.isSelected();
        }
    }, 5);
}