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.jtalks.tests.jcommune.webdriver.topic.Topics.java

License:Open Source License

/**
  * Sets state for checkbox element//  w w  w . j  av a 2s  .com
  * 
  * @param checkboxElement
  *            the checkbox web element
  * @param state
  *            the state: true - checked, false - unchecked, null - the
  *            element is not used
  */

 private static void setCheckboxState(WebElement checkboxElement, Boolean state) {
     if (state == null) {
         return;
     }
     if (state && !checkboxElement.isSelected()) {
         checkboxElement.click();
     } else if (!state && checkboxElement.isSelected()) {
         checkboxElement.click();
     }
 }

From source file:org.jwatter.browser.WebDriverWebAutomationFramework.java

License:Apache License

@Override
public String selectedOptionInDropDownMenuWithId(String id) throws NoSuchElementException {
    WebElement select = findDropDownMenuWithId(id);
    List<WebElement> options = select.findElements(By.tagName("option"));
    for (WebElement option : options) {
        if (option.isSelected()) {
            return option.getText();
        }/*from ww w  .  j a va  2  s  .  c om*/
    }
    return null;
}

From source file:org.jwatter.browser.WebDriverWebAutomationFramework.java

License:Apache License

@Override
public String selectedOptionInDropDownMenuWithName(String name, int which)
        throws NoSuchElementException, Exception {
    WebElement select = findDropDownMenuWithName(name, which);
    List<WebElement> options = select.findElements(By.tagName("option"));
    for (WebElement option : options) {
        if (option.isSelected()) {
            return option.getText();
        }/*w w w .j av a2s.  c  om*/
    }
    return null;
}

From source file:org.keycloak.testsuite.console.page.authentication.flows.FlowsTable.java

License:Open Source License

public Map<String, String> getFlowsAliasesWithRequirements() {
    Map<String, String> flows = new LinkedHashMap<>();
    List<WebElement> aliases = tbody.findElements(By.xpath("//span[@class='ng-binding']"));

    for (WebElement alias : aliases) {
        List<WebElement> requirementsOptions = alias
                .findElements(By.xpath(".//../parent::*//input[@type='radio']"));
        for (WebElement requirement : requirementsOptions) {
            if (requirement.isSelected()) {
                flows.put(getTextFromElement(alias), requirement.getAttribute("value"));
            }/* ww w.  jav a 2  s. c o  m*/
        }
    }
    return flows;
}

From source file:org.kuali.kra.test.infrastructure.KcSeleniumHelper.java

License:Educational Community License

/**
 * Gets the value of a checkbox.//from   w  w w  .j  a  va  2  s . co  m
 * 
 * @param element the located parent element
 */
private final String getCheckbox(final WebElement element) {
    return BooleanUtils.toString(element.isSelected(), "on", "off");
}

From source file:org.kuali.kra.test.infrastructure.KcSeleniumHelper.java

License:Educational Community License

/**
 * Gets the value of a radio button./*from  w  ww  .j av a  2s.com*/
 * 
 * @param locator the id, name, title, or link name of the element to set depending on the value of {@code exact}
 * @param exact whether the locator should match exactly
 */
private final String getRadio(final WebElement element) {
    return BooleanUtils.toString(element.isSelected(), "on", "off");
}

From source file:org.kuali.kra.test.infrastructure.KcSeleniumHelper.java

License:Educational Community License

/**
 * Sets the value of a checkbox.//from  w  ww  . jav  a2 s .  c  om
 * 
 * @param element the located parent element
 * @param value the new value of the element
 */
private final void setCheckbox(final WebElement element, final String value) {
    boolean booleanValue = BooleanUtils.toBoolean(value);
    if ((booleanValue && !element.isSelected()) || (!booleanValue && element.isSelected())) {
        element.click();
    }
}

From source file:org.kuali.rice.testtools.selenium.WebDriverAftBase.java

License:Educational Community License

protected void check(By by) throws InterruptedException {
    WebElement element = findElement(by);

    if (!element.isSelected()) {
        element.click();/*  www .ja  v a 2s  . c om*/
    }
}

From source file:org.kuali.rice.testtools.selenium.WebDriverAftBase.java

License:Educational Community License

protected void uncheck(By by) throws InterruptedException {
    WebElement element = findElement(by);
    if (element.isSelected()) {
        element.click();/*w ww  .  j a  va 2 s . co  m*/
    }
}

From source file:org.mousephenotype.www.SearchPageTest.java

License:Apache License

@Test
//@Ignore// w ww  .  ja  v  a 2s  .  co  m
public void testTickingFacetFilters() throws Exception {
    testCount++;
    System.out.println();
    String testName = "testTickingFacetFilters";

    System.out.println("\n\n----- " + testName + " -----");
    System.out.println("TESTING clicking on a facet checkbox will add a filter to the filter summary box");
    System.out.println("TESTING removing a filter on the list will uncheck a corresponding checkbox");

    String message;
    successList.clear();
    errorList.clear();
    String target = baseUrl + "/search";
    logger.debug("target Page URL: " + target);
    SearchPage searchPage = new SearchPage(driver, timeout_in_seconds, target, phenotypePipelineDAO, baseUrl);

    // For each core:
    //   Click the first subfacet.
    //   Check that it is selected.
    //   Check that there is a filter matching the selected facet above the Genes facet.
    //   Click the first subfacet again to unselect it.
    //   Check that it is unselected.
    //   Check that there is no filter matching the just-unselected facet above the Genes facet.
    for (String core : cores) {
        String subfacetCheckboxCssSelector = "li#" + core + " li.fcat input[type='checkbox']";
        String subfacetTextCssSelector = "li#" + core + " li.fcat span.flabel";
        int iterationErrorCount = 0;
        Facet facet = searchPage.getFacetByCoreName(core);
        searchPage.openFacet(facet); // Open facet if it is not alreay opened.

        WebElement firstSubfacetElement = wait
                .until(ExpectedConditions.elementToBeClickable(By.cssSelector(subfacetCheckboxCssSelector)));
        firstSubfacetElement.click(); // Select the first subfacet.

        searchPage.openFacet(facet); // Re-open the facet as, by design, it closed after the click() above.
        if (!firstSubfacetElement.isSelected()) { // Verify that the subfacet is selected.
            iterationErrorCount++;
            message = "Failed to check input filter for " + facet + " facet.";
            errorList.add(message);
            logger.error(message);
        }

        // Check that there is a filter matching the selected facet above the Genes facet.
        String facetText = driver.findElement(By.cssSelector(subfacetTextCssSelector)).getText();
        HashMap<Facet, SearchPage.FacetFilter> facetFilterHash = searchPage.getFacetFilter();
        List<String> facetFilterText = facetFilterHash.get(facet).subfacetTexts;
        boolean found = false;
        for (String facetFilter : facetFilterText) {
            if (facetFilter.contains(facetText)) {
                found = true;
                break;
            }
        }
        if (!found) {
            iterationErrorCount++;
            message = "ERROR: Couldn't find subfacet '" + facetText + "' in facet " + facet;
            errorList.add(message);
            logger.error(message);
        }

        searchPage.openFacet(facet); // Open facet if it is not alreay opened.
        firstSubfacetElement.click(); // Deselect the first subfacet.

        searchPage.openFacet(facet); // Re-open the facet as, by design, it closed after the click() above.

        // The page becomes stale after the click() above, so we must re-fetch the WebElement objects.
        firstSubfacetElement = wait
                .until(ExpectedConditions.elementToBeClickable(By.cssSelector(subfacetCheckboxCssSelector)));

        if (firstSubfacetElement.isSelected()) { // Verify that the subfacet is no longer selected.
            iterationErrorCount++;
            message = "Failed to uncheck input filter for " + facet + " facet.";
            errorList.add(message);
            logger.error(message);
        }

        // Check that there are no filters.
        if (searchPage.hasFilters()) {
            iterationErrorCount++;
            message = "ERROR: Expected filters to be cleared, but there were filters in place for facet "
                    + facet;
            errorList.add(message);
            logger.error(message);
        }

        if (iterationErrorCount == 0) {
            logger.info("   " + core + " OK");
            successList.add(core);
        }

        searchPage.clearFilters();
    }
    System.out.println();
    if (successList.size() == params.size()) {
        System.out.println("[PASSED] - " + testName);
        sumSuccessList.add("passed");
    } else {
        System.out.println("[FAILED] - " + testName + "\n" + StringUtils.join(errorList, "\n"));
        sumErrorList.add("[FAILED] - " + testName + "\n" + StringUtils.join(errorList, "\n"));
        fail("There were " + sumErrorList.size() + " errors.");
    }
    System.out.println();
}