@Override public boolean apply(Driver driver, WebElement element) { return element.isSelected(); }
@Override public boolean apply(Driver driver, WebElement element) { return element.isSelected(); }
private void setSelected(WebElement option) { if (!option.isSelected()) { option.click(); } } }
@Override public String actualValue(Driver driver, WebElement element) { return String.valueOf(element.isSelected()); } };
@Override public String actualValue(Driver driver, WebElement element) { return String.valueOf(element.isSelected()); } };
private Describe isSelected(WebElement element) { try { if (element.isSelected()) { sb.append(' ').append("selected:true"); } } catch (UnsupportedOperationException ignore) { } catch (InvalidElementStateException ignore) { } return this; }
@Override public WebElement execute(SelenideElement proxy, WebElementSource locator, Object[] args) { boolean selected = (Boolean) args[0]; WebElement element = locator.getWebElement(); if (!element.isDisplayed()) { throw new InvalidStateException(locator.driver(), "Cannot change invisible element"); } String tag = element.getTagName(); if (!tag.equals("option")) { if (tag.equals("input")) { String type = element.getAttribute("type"); if (!type.equals("checkbox") && !type.equals("radio")) { throw new InvalidStateException(locator.driver(), "Only use setSelected on checkbox/option/radio"); } } else { throw new InvalidStateException(locator.driver(), "Only use setSelected on checkbox/option/radio"); } } if (element.getAttribute("readonly") != null || element.getAttribute("disabled") != null) { throw new InvalidStateException(locator.driver(), "Cannot change value of readonly/disabled element"); } if (element.isSelected() != selected) { click.execute(proxy, locator, NO_ARGS); } return proxy; } }
@Test void dependencyUncheckedWhenHidden() throws Exception { HomePage page = toHome(); // bur: [2.1.4.RELEASE,2.2.0.BUILD-SNAPSHOT) page.advanced(); page.dependency("org.acme:bur").click(); assertThat(page.dependency("org.acme:bur").isSelected()).isTrue(); page.bootVersion("1.5.17.RELEASE"); assertThat(page.dependency("org.acme:bur").isEnabled()).isFalse(); page.bootVersion("2.1.4.RELEASE"); assertThat(page.dependency("org.acme:bur").isEnabled()).isTrue(); assertThat(page.dependency("org.acme:bur").isSelected()).isFalse(); }
private Object getInputValue(WebElement input) { Object value = null; 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; }
Assert.assertFalse(webDriver.findElement(By.xpath("//input[@value='app-password.write']")).isSelected()); Assert.assertFalse(webDriver.findElement(By.xpath("//input[@value='app-scim.userids']")).isSelected()); Assert.assertTrue(webDriver.findElement(By.xpath("//input[@value='app-cloud_controller.read']")).isSelected()); Assert.assertTrue(webDriver.findElement(By.xpath("//input[@value='app-cloud_controller.write']")).isSelected()); Assert.assertTrue(webDriver.findElement(By.xpath("//input[@value='app-password.write']")).isSelected()); Assert.assertTrue(webDriver.findElement(By.xpath("//input[@value='app-scim.userids']")).isSelected()); Assert.assertTrue(webDriver.findElement(By.xpath("//input[@value='app-cloud_controller.read']")).isSelected()); Assert.assertTrue(webDriver.findElement(By.xpath("//input[@value='app-cloud_controller.write']")).isSelected());
public boolean isElementSelected(String elementId) { try { return browser.driver.findElement(By.id(elementId)).isSelected(); } catch (NoSuchElementException e) { return false; } }
public boolean getInstructorDisplayedToStudents(int instrNum) { String isDisplayedToStudentsCheckboxSelector = "#instructorTable" + instrNum + " input[name='" + Const.ParamsNames.INSTRUCTOR_IS_DISPLAYED_TO_STUDENT + "']"; return browser.driver.findElement(By.cssSelector(isDisplayedToStudentsCheckboxSelector)).isSelected(); }
public boolean isPrivilegeCheckboxInModalChecked(String privilege) { By selector = By.cssSelector("#tunePermissionsDivForInstructorAll input[type='checkbox'][name='" + privilege + "']"); WebElement checkbox = browser.driver.findElement(selector); return checkbox.isSelected(); }
public boolean isPrivilegeCheckboxInPermissionDivChecked(int instructorIndex, String privilege) { By selector = By.cssSelector("#tunePermissionsDivForInstructor" + instructorIndex + " input[type='checkbox'][name='" + privilege + "']"); WebElement checkbox = browser.driver.findElement(selector); return checkbox.isSelected(); }
public boolean isCheckboxChecked(String checkboxClass, String checkboxValue, int questionNumber) { By checkboxSelector = By.cssSelector("#questionTable-" + questionNumber + " input[value='" + checkboxValue + "']." + checkboxClass); WebElement checkbox = browser.driver.findElement(checkboxSelector); return checkbox.isSelected(); }
/** * 'uncheck' the check box, if it is already 'checked'. * No action taken if it is not already 'checked'. */ protected void markCheckBoxAsUnchecked(WebElement checkBox) { if (checkBox.isSelected()) { click(checkBox); } }
/** * 'check' the check box, if it is not already 'checked'. * No action taken if it is already 'checked'. */ protected void markCheckBoxAsChecked(WebElement checkBox) { waitForElementVisibility(checkBox); if (!checkBox.isSelected()) { click(checkBox); } }
/** * 'check' the radio button, if it is not already 'checked'. * No action taken if it is already 'checked'. */ protected void markRadioButtonAsChecked(WebElement radioButton) { waitForElementVisibility(radioButton); if (!radioButton.isSelected()) { click(radioButton); } }
public boolean isRadioButtonChecked(int rowIndex) { WebElement button = browser.driver.findElement(By.id("copyTableModal")) .findElements(By.tagName("tr")) .get(rowIndex + 1).findElement(By.tagName("input")); return button.isSelected(); }
public void submitWithoutConfirmationEmail() { WebElement sendEmailCheckbox = browser.driver.findElement(By.name(Const.ParamsNames.SEND_SUBMISSION_EMAIL)); if (sendEmailCheckbox.isSelected()) { click(sendEmailCheckbox); } clickSubmitButton(); }