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:io.selendroid.client.waiter.WaitingConditions.java

License:Apache License

public static Callable<WebElement> elementSelectionToBe(final WebElement element, final boolean selected) {
    return new Callable<WebElement>() {
        public WebElement call() throws Exception {
            if (element.isSelected() == selected) {
                return element;
            }//w  w  w .j  ava2  s  .c o m

            return null;
        }
    };
}

From source file:io.selendroid.nativetests.NativeElementInteractionTest.java

License:Apache License

@Test
public void shouldGetSelectedStateOfElement() {
    openStartActivity();//from   w  w  w  .  j  a  v a2 s.  co m
    WebElement checkBox = driver().findElement(By.id("input_adds_check_box"));
    Assert.assertEquals(checkBox.isSelected(), true);
    checkBox.click();
    Assert.assertEquals(checkBox.isSelected(), false);
}

From source file:io.selendroid.nativetests.NativeElementInteractionTest.java

License:Apache License

@Test
public void shouldScrollAndEnterText() {
    openStartActivity();/*from   ww w  . j  a  v a2s  .  com*/

    driver().findElement(By.id("startUserRegistration")).click();
    new WebDriverWait(driver(), 5).until(ExpectedConditions.presenceOfElementLocated(By.id("inputUsername")));
    WebElement acceptAddsCheckbox = driver().findElement(By.id("input_adds"));
    if (acceptAddsCheckbox.isSelected()) {
        acceptAddsCheckbox.click();
        Assert.assertEquals(false, acceptAddsCheckbox.isSelected());
    } else {
        acceptAddsCheckbox.click();
        Assert.assertEquals(true, acceptAddsCheckbox.isSelected());
    }
}

From source file:io.selendroid.tests.UserRegistrationTest.java

License:Apache License

private void registerUser(UserDO user) throws Exception {
    WebElement button = driver().findElement(By.id("startUserRegistration"));

    button.click();//from  ww  w  .  jav  a  2  s. c o  m

    WebElement username = driver().findElement(By.id("inputUsername"));

    username.sendKeys(user.getUsername());
    WebElement nameInput = driver().findElement(By.id("inputName"));
    Assert.assertEquals(nameInput.getText(), "Mr. Burns");
    nameInput.clear();
    nameInput.sendKeys(user.getName());

    driver().findElement(By.id("inputEmail")).sendKeys(user.getEmail());
    driver().findElement(By.id("inputPassword")).sendKeys(user.getPassword());
    try {
        nameInput.submit();
        Assert.fail("submit is not supported by SelendroidNativeDriver");
    } catch (WebDriverException e) {
        // expected behavior
    }

    driver().findElement(By.id("input_preferedProgrammingLanguage")).click();
    driver().findElement(By.linkText(user.getProgrammingLanguage().getValue())).click();
    WebElement acceptAddsCheckbox = driver().findElement(By.id("input_adds"));
    Assert.assertEquals(acceptAddsCheckbox.isSelected(), false);
    acceptAddsCheckbox.click();

    Assert.assertEquals(driver().getCurrentUrl(), "and-activity://RegisterUserActivity");
    try {
        driver().getTitle();
        Assert.fail("Get title is not supported by SelendroidNativeDriver");
    } catch (WebDriverException e) {
        // expected behavior
    }

    driver().findElement(By.id("btnRegisterUser")).click();
}

From source file:io.selendroid.webviewdrivertests.WebElementFindingTest.java

License:Apache License

@Test
public void testShouldfindAnElementBasedOnId() {
    openWebdriverTestPage(HtmlTestData.FORM_PAGE);
    waitFor(pageTitleToBe(driver(), "We Leave From Here"), 10, TimeUnit.SECONDS);

    WebElement element = driver().findElement(By.id("checky"));
    Assert.assertEquals(element.isSelected(), false);
}

From source file:io.selendroid.webviewdrivertests.WebElementInteractionTest.java

License:Apache License

@Test()
public void shouldClickOnElement() {
    openWebdriverTestPage(HtmlTestData.FORM_PAGE);
    WebElement ckeckbox = driver().findElement(By.id("checkedchecky"));
    Assert.assertEquals(ckeckbox.isSelected(), true);
    ckeckbox.click();// ww  w. ja  v a2 s .com
    Assert.assertEquals(ckeckbox.isSelected(), false);
}

From source file:io.selendroid.webviewdrivertests.WebElementInteractionTest.java

License:Apache License

@Test
public void shouldGetSelectedStateOfElement() {
    givenWebViewWithFormPageLoaded();//from w  w w .  j  a  v a2  s  .  c  om

    WebElement element = driver().findElement(By.id("checky"));
    Assert.assertEquals(element.isSelected(), false);
    element.click();
    Assert.assertEquals(element.isSelected(), true);
}

From source file:io.spring.initializr.web.project.HomePage.java

License:Apache License

private Object getInputValue(WebElement input) {
    Object value = null;/*from  w  w w .  j  a va  2s  .  c o  m*/
    String type = input.getAttribute("type");
    if ("select".equals(input.getTagName())) {
        Select select = new Select(input);
        if (select.isMultiple()) {
            value = select.getAllSelectedOptions().stream().map(this::getValue).collect(Collectors.toList());
        } else {
            value = getValue(select.getFirstSelectedOption());
        }
    } else if (Arrays.asList("checkbox", "radio").contains(type)) {
        if (input.isSelected()) {
            value = getValue(input);
        } else {
            if (Objects.equals(type, "checkbox")) {
                value = false;
            }
        }
    } else {
        value = getValue(input);
    }
    return value;
}

From source file:jhc.redsniff.webdriver.matchers.ElementSelectedMatcher.java

License:Apache License

@Override
protected ElementSelectedState stateOf(WebElement element) {
    return element.isSelected() ? SELECTED : UNSELECTED;
}

From source file:jhc.redsniff.wicket.WicketEnabledTester.java

License:Apache License

public void tickByName(String checkBoxId, boolean value) {
    WebElement checkBox = find(itemByName(checkBoxId));
    if (checkBox.isSelected() != value)
        tick(itemByName(checkBoxId));/*from www  .j a v  a2  s.c o  m*/
    assertThatThe(itemByName(checkBoxId), hasSelectedState(value));
}