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

License:Apache License

public void deselectByText(final String text) {
    SeltafTestLogger.logWebStep(null, "deselect text\"" + text + "\" on " + toHTML(), false);
    findElement();//w  w  w .ja v  a  2s .c  o m
    for (WebElement option : options) {
        if (option.getAttribute("text").equals(text)) {
            if (option.isSelected()) {
                option.click();
            }

            break;
        }
    }
}

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

License:Apache License

public void deselectByValue(final String value) {
    SeltafTestLogger.logWebStep(null, "deselect value\"" + value + "\" on " + toHTML(), false);
    findElement();//from   ww  w. ja va 2 s  . co  m
    for (WebElement option : options) {
        if (option.getAttribute("value").equals(value)) {
            if (option.isSelected()) {
                option.click();
            }

            break;
        }
    }

}

From source file:com.sonar.it.jenkins.orchestrator.JenkinsOrchestrator.java

License:Open Source License

public JenkinsOrchestrator enableInjectionVars(boolean enable) {
    driver.get(server.getUrl() + "/configure");

    WebElement checkbox = findElement(By.name("enableBuildWrapper"));
    if (checkbox.isSelected() != enable) {
        checkbox.click();/*from   w w  w.  j  a  va 2 s .  c  o  m*/
    }
    findElement(buttonByText("Save")).click();
    return this;
}

From source file:com.springer.omelet.driver.DriverUtility.java

License:Apache License

/***
 * Forcefully check/uncheck checkbox irrespective of the state(Element
 * should be visible)/*from ww  w  .ja v a2 s  .  co  m*/
 * 
 * @param webElement
 *            :Check box element
 * @param CHECK_UNCHECK
 *            enum
 */
public static void checkUncheckCheckBox(WebElement webElement, CHECK_UNCHECK checkUnCheck) {
    boolean checked = webElement.isSelected();
    if (checked) {
        if (checkUnCheck.toString().equalsIgnoreCase("uncheck")) {
            webElement.click();
        }
    } else {
        if (checkUnCheck.toString().equalsIgnoreCase("check")) {
            webElement.click();
        }
    }
}

From source file:com.technophobia.webdriver.substeps.impl.AssertionWebDriverSubStepImplementations.java

License:Open Source License

/**
 * Check that the current element, a checkbox is checked or not
 * // w  ww.ja  v  a 2 s  .  c om
 * @example AssertCheckBox checked=true/false
 * @section Assertions
 * @param checkedString
 *            whether the radio button is checked or not
 */
@Step("AssertCheckBox checked=\"?([^\"]*)\"?")
public void assertCheckBoxIsChecked(final String checkedString) {

    // check that the current element is not null and is a radio btn
    final WebElement currentElem = webDriverContext().getCurrentElement();

    assertElementIs(currentElem, "input", "checkbox");

    // check the state
    final boolean checked = Boolean.parseBoolean(checkedString.trim());
    if (checked) {
        Assert.assertTrue("expecting checkbox to be checked", currentElem.isSelected());
    } else {
        Assert.assertFalse("expecting checkbox not to be checked", currentElem.isSelected());
    }
}

From source file:com.technophobia.webdriver.substeps.impl.AssertionWebDriverSubStepImplementations.java

License:Open Source License

/**
 * Check that the current element, a radio button, is checked or not
 * /*from  www .  j  a  va2s  .c  o  m*/
 * @example AssertRadioButton checked=true/false
 * @section Assertions
 * @param checkedString
 *            whether the radio button is checked or not
 */
@Step("AssertRadioButton checked=\"?([^\"]*)\"?")
public void assertRadioButtonIsChecked(final String checkedString) {

    // check that the current element is not null and is a radio btn
    final WebElement currentElem = webDriverContext().getCurrentElement();

    assertElementIs(currentElem, "input", "radio");

    // check the state
    final boolean checked = Boolean.parseBoolean(checkedString.trim());
    if (checked) {
        Assert.assertTrue("expecting radio button to be checked", currentElem.isSelected());
    } else {
        Assert.assertFalse("expecting radio button not to be checked", currentElem.isSelected());
    }
}

From source file:com.technophobia.webdriver.substeps.impl.FormWebDriverSubStepImplementations.java

License:Open Source License

/**
 * Asserts that the select with the specified id has the specified option text selected
 *
 * @example AssertSelect id="select_id" text="number two option" is currently selected
 * @section Form/*from w w w .  j a va  2 s .c o  m*/
 * @param id the id of the select
 * @param value the text value of the option
 */
@Step("AssertSelect id=\"([^\"]*)\" text=\"([^\"]*)\" is currently selected")
public void assertOptionIsSelected(final String id, final String value) {
    logger.debug("Asserting select box with id " + id + " has option " + value + " selected");
    final WebElement select = this.locator.findById(id);

    final List<WebElement> options = getOptions(select);
    for (final WebElement option : options) {

        if (option.getText().equals(value)) {
            Assert.assertTrue("option text: " + value + "is not selected", option.isSelected());
            break;
        }
    }
}

From source file:com.technophobia.webdriver.substeps.impl.FormWebDriverSubStepImplementations.java

License:Open Source License

/**
 * Asserts that the select with the specified id does not have the specified option text selected
 *
 * @example AssertSelect id="select_id" text="number one option" is not currently selected
 * @section Form/*from w  w  w .  j av  a  2 s .co m*/
 * @param id the id of the select
 * @param value the text value of the option that shouldn't be selected
 */
@Step("AssertSelect id=\"([^\"]*)\" text=\"([^\"]*)\" is not currently selected")
public void assertOptionIsNotSelected(final String id, final String value) {
    logger.debug("Asserting select box with id " + id + " has option " + value + " not selected");
    final WebElement select = this.locator.findById(id);

    final List<WebElement> options = getOptions(select);
    for (final WebElement option : options) {

        if (option.getText().equals(value)) {
            Assert.assertFalse(option.isSelected());
            break;
        }
    }
}

From source file:com.technophobia.webdriver.substeps.impl.FormWebDriverSubStepImplementations.java

License:Open Source License

/**
 * Sets the checkbox value.//from www. ja v  a2s . c o  m
 * 
 * @example
 * @param checkboxField
 *            the checkbox field
 * @param value
 *            the value
 */
protected void setCheckboxValue(final WebElement checkboxField, final boolean value) {
    logger.debug("About to set checkbox " + checkboxField + "to " + (value ? "checked" : "not checked"));
    if (checkboxField.isSelected() && !value) {
        checkboxField.click();
    } else if (!checkboxField.isSelected() && value) {
        checkboxField.click();
    }
}

From source file:com.thoughtworks.selenium.webdriven.commands.Check.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();/*from  w  ww.  j  av a2 s .  c om*/
    }

    return null;
}