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.arquillian.droidium.showcase.screenshooter.test01.SelendroidTestAppTestCase.java

License:Apache License

/**
 * Simple test which tries to register some user.
 *
 * @param screenshooter takes screenshots of {@code device}
 * @param device Android device itself, it is not needed in tests as such since we interact only with {@code WebDriver}
 *        injection.//from  w  w w  . ja va  2  s.  c o  m
 * @param driver {@code WebDriver} injection which sends commands to Selendroid server installed on the Android device.
 */
@Test
@InSequence(1)
public void test01(@ArquillianResource AndroidDevice device) {

    device.getActivityManager().startActivity("io.selendroid.testapp.HomeScreenActivity");

    // where to save taken screenshots, by default to target/screenshots
    screenshooter.setScreenshotTargetDir("target/screenshots-1");

    // take it!
    screenshooter.takeScreenshot();

    // Go to user registration
    driver.findElement(By.id("startUserRegistration")).click();

    // take it as GIF, by default, it is taken as PNG
    screenshooter.setMessage("taking gif").takeScreenshot(ScreenshotType.GIF);

    // enter nick
    WebElement userName = driver.findElement(By.id("inputUserName"));
    userName.sendKeys(USER_NAME);
    Assert.assertEquals(userName.getText(), USER_NAME);

    // enter e-mail
    WebElement inputEmail = driver.findElement(By.id("inputEmail"));
    inputEmail.sendKeys(USER_EMAIL);
    Assert.assertEquals(inputEmail.getText(), USER_EMAIL);

    // enter password
    WebElement inputPassword = driver.findElement(By.id("inputPassword"));
    inputPassword.sendKeys(USER_PASSWORD);
    Assert.assertEquals(inputPassword.getText(), USER_PASSWORD);

    // check value in name field, clear it and write new one
    WebElement inputName = driver.findElement(By.id("inputName"));
    Assert.assertEquals(inputName.getText(), USER_REAL_OLD);
    inputName.clear();
    inputName.sendKeys(USER_REAL_NAME);
    Assert.assertEquals(inputName.getText(), USER_REAL_NAME);

    // enter favorite language
    driver.findElement(By.id("input_preferedProgrammingLanguage")).click();
    driver.findElement(By.linkText(USER_PRGRAMMING_LANGUAGE)).click();

    // accept adds checkbox
    WebElement acceptAddsCheckbox = driver.findElement(By.id("input_adds"));
    Assert.assertEquals(acceptAddsCheckbox.isSelected(), false);

    acceptAddsCheckbox.click();

    screenshooter.setScreenshotTargetDir("target/screenshots-2");

    // from now on, take all images as BMP if not specified otherwise
    screenshooter.setScreenshotType(ScreenshotType.BMP);

    // you can name it, it will be PNG image by default
    screenshooter.takeScreenshot("myscreenshot1");

    // register
    driver.findElement(By.id("btnRegisterUser")).click();

    // or you can specify file format as well
    screenshooter.takeScreenshot("myscreenshot2", ScreenshotType.JPEG);

}

From source file:org.auraframework.components.ui.inputMultiSelect.BaseInputMultiSelect.java

License:Apache License

private void verifyOptionSelectDeselct(String optionLabel, boolean isSelected) {
    WebElement option = findDomElement(By.xpath(String.format(optionLocatorString, optionLabel)));
    if (isSelected) {
        assertTrue("Option '" + optionLabel + "' should be selected", option.isSelected());
    } else {/* w ww  .j  a  v  a 2 s.  co  m*/
        assertFalse("Option '" + optionLabel + "' should be deselected", option.isSelected());
    }
}

From source file:org.auraframework.components.ui.inputSelect.BaseInputSelectUI.java

License:Apache License

private void verifyOptionSelectDeselct(String optionLabel, boolean isSelected) {
    WebElement option = findDomElement(By.xpath(String.format(OPTION_LOCATOR_STRING, optionLabel)));
    if (isSelected) {
        assertTrue("Option '" + optionLabel + "' should be selected", option.isSelected());
    } else {/*from  w  ww .  j  a  v a2  s  . com*/
        assertFalse("Option '" + optionLabel + "' should be deselected", option.isSelected());
    }
}

From source file:org.auraframework.components.ui.inputSelect.InputSelectUITest.java

License:Apache License

private void verifyOptionSelectDeselect(String optionLabel, boolean isSelected) {
    WebElement option = getOption(optionLabel);
    String cmpValue = getComponentValue(selectId);
    if (isSelected) {
        assertTrue("Option '" + optionLabel + "' should be selected", option.isSelected());
        assertEquals("input select should have the correct v.value", optionLabel, cmpValue);
    } else {/*from ww w.  j a v a 2s. co  m*/
        assertFalse("Option '" + optionLabel + "' should be deselected", option.isSelected());
        assertFalse("v.value should be different from the selected option", optionLabel.equals(cmpValue));
    }
}

From source file:org.craftercms.cstudio.share.selenium.forms.CheckboxGroupSimpleTest.java

License:Open Source License

private void test_checkbox_group_simple(WebDriver driver) {
    // Login/*from w w  w  . j  a  va2 s  . co  m*/
    CStudioSeleniumUtil.try_login(driver, CStudioSeleniumUtil.AUTHOR_USER, CStudioSeleniumUtil.AUTHOR_PASSWORD,
            true);

    // Navigate to Widget
    CStudioSeleniumUtil.navigate_to_checkbox_group_simple_widget(driver);

    // Wait until checkboxes are rendered
    new WebDriverWait(driver, CStudioSeleniumUtil.SHORT_TIMEOUT).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.findElement(By.tagName("body")).getText().contains("From the Inside");
        }
    });

    // Verify checkboxes are working fine
    List<WebElement> elements = driver.findElements(By.className("cstudio-xforms-checkbox-simple-checkbox"));
    assertEquals(6, elements.size());
    for (WebElement e : elements) {
        e.click();
        assertTrue(e.isSelected());
        e.click();
        assertFalse(e.isSelected());
    }

    // Close driver
    CStudioSeleniumUtil.exit(driver);
}

From source file:org.craftercms.cstudio.share.selenium.forms.CheckboxSimpleTest.java

License:Open Source License

private void test_checkbox_simple(WebDriver driver) {
    // Login/*from  w w w  . j  a va 2s . com*/
    CStudioSeleniumUtil.try_login(driver, CStudioSeleniumUtil.AUTHOR_USER, CStudioSeleniumUtil.AUTHOR_PASSWORD,
            true);

    // Navigate to Widget
    CStudioSeleniumUtil.navigate_to_checkbox_simple_widget(driver);

    // Wait until checkboxes are rendered
    new WebDriverWait(driver, CStudioSeleniumUtil.SHORT_TIMEOUT).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.findElement(By.tagName("body")).getText().contains("Default True");
        }
    });

    // Test hint
    CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-11$checkEmptyId$xf-188$$i"));
    CStudioSeleniumUtil.wait_until_displayed(driver, CStudioSeleniumUtil.SHORT_TIMEOUT, By.id("yui-gen5_c"));
    CStudioSeleniumUtil.click_on(driver, By.xpath("/html/body/div/div/div/div/div/div[2]/form/div[2]/div/a"));
    CStudioSeleniumUtil.wait_until_not_displayed(driver, CStudioSeleniumUtil.SHORT_TIMEOUT,
            By.id("yui-gen5_c"));

    // Test hint
    CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-11$checkTrueId$xf-198$$i"));
    CStudioSeleniumUtil.wait_until_displayed(driver, CStudioSeleniumUtil.SHORT_TIMEOUT, By.id("yui-gen5_c"));
    CStudioSeleniumUtil.click_on(driver, By.xpath("/html/body/div/div/div/div/div/div[2]/form/div[2]/div/a"));
    CStudioSeleniumUtil.wait_until_not_displayed(driver, CStudioSeleniumUtil.SHORT_TIMEOUT,
            By.id("yui-gen5_c"));

    // Test checkbox value
    WebElement element = driver.findElement(By.id("xf-4$xf-11$checkEmptyId$checkbox-simple$$e0"));
    assertFalse(element.isSelected());
    element.click();
    assertTrue(element.isSelected());

    // Test checkbox value
    element = driver.findElement(By.id("xf-4$xf-11$checkTrueId$checkbox-simple$$e0"));
    assertTrue(element.isSelected());
    element.click();
    assertFalse(element.isSelected());

    // Close driver
    CStudioSeleniumUtil.exit(driver);
}

From source file:org.eclipse.che.selenium.core.webdriver.SeleniumWebDriverHelper.java

License:Open Source License

/**
 * Sets given {@code isCheckedWebElement} to specified state and waits its state
 *
 * <p>Note! Uses only for checkboxes and radio buttons.
 *
 * @param isCheckedWebElement element which should be selected
 * @param setWebElement element which should be clicked to change the state
 * @param state state of given element (true if the given element should be selected)
 *//*  w  w  w  .j  a  v  a  2 s.co m*/
public void waitAndSetCheckbox(WebElement isCheckedWebElement, WebElement setWebElement, boolean state) {
    if (state) {
        if (!isCheckedWebElement.isSelected()) {
            waitAndClick(setWebElement);
            waitElementIsSelected(isCheckedWebElement);
        }
    } else {
        if (isCheckedWebElement.isSelected()) {
            waitAndClick(setWebElement);
            waitElementIsNotSelected(isCheckedWebElement);
        }
    }
}

From source file:org.eclipse.che.selenium.pageobject.Preferences.java

License:Open Source License

/**
 * set all flag in once position (check or uncheck) on the editor settings section
 *
 * @param valueOfFlag value of flag/*from w w  w . j  av a 2s.c  om*/
 * @param settingsList list of settings
 */
public void setAllCheckboxSettingsInEditorWidget(FlagForEditorWidget valueOfFlag, List<String> settingsList) {
    for (String settingsItem : settingsList) {
        if (seleniumWebDriverHelper.waitVisibilityAndGetAttribute(By.xpath(format(EDITOR_INPUT, settingsItem)),
                "type", REDRAW_UI_ELEMENTS_TIMEOUT_SEC).equals("checkbox")) {
            WebElement checkbox = seleniumWebDriverHelper
                    .waitPresence(By.xpath(format(EDITOR_INPUT, settingsItem)));
            WebElement spanCheckbox = seleniumWebDriverHelper.waitPresence(
                    By.xpath(format(EDITOR_CHECKBOX_SPAN_XPATH, settingsItem)), REDRAW_UI_ELEMENTS_TIMEOUT_SEC);
            switch (valueOfFlag) {
            case CHECK:
                if (!checkbox.isSelected()) {
                    actionsFactory.createAction(seleniumWebDriver).moveToElement(spanCheckbox).perform();
                    spanCheckbox.click();
                }
                break;
            default:
                if (checkbox.isSelected()) {
                    actionsFactory.createAction(seleniumWebDriver).moveToElement(spanCheckbox).perform();
                    spanCheckbox.click();
                }
                break;
            }
        }
    }
}

From source file:org.eclipse.skalli.selenium.pageobjects.ext.editform.BasicsExtensionEditForm.java

License:Open Source License

public void checkDeletedCheckBox(boolean checked) {
    WebElement deletedCheckBox = getDeletedCheckBox();

    if (checked && !deletedCheckBox.isSelected()) {
        deletedCheckBox.click();//from   w w w  .jav a  2 s .  com
    }

    if (!checked && deletedCheckBox.isSelected()) {
        deletedCheckBox.click();
    }
}

From source file:org.eclipse.skalli.selenium.pageobjects.ext.editform.RatingsAndReviewExtensionEditForm.java

License:Open Source License

public void checkAllowAnonymusReviewsCheckBox(boolean checked) {
    WebElement allowAnonymusReviewsCheckBox = getAllowAnonymusReviewsCheckBox();

    if (checked && !allowAnonymusReviewsCheckBox.isSelected()) {
        allowAnonymusReviewsCheckBox.click();
    }//from  w  w  w  .j  a  v  a  2  s. c  o  m

    if (!checked && allowAnonymusReviewsCheckBox.isSelected()) {
        allowAnonymusReviewsCheckBox.click();
    }
}