Example usage for org.openqa.selenium WebElement getCssValue

List of usage examples for org.openqa.selenium WebElement getCssValue

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement getCssValue.

Prototype

String getCssValue(String propertyName);

Source Link

Document

Get the value of a given CSS property.

Usage

From source file:com.github.fscheffer.arras.demo.IconIT.java

License:Apache License

private void assertFontSize(WebElement element, Integer expected) {
    Assert.assertEquals(element.getCssValue("font-size"), expected.toString() + "px");
}

From source file:com.github.fscheffer.arras.demo.LightboxIT.java

License:Apache License

@Test
public void testFixedSize() {

    // fixed size
    openLightbox(By.linkText("San Joaquin River (Fixed size)"));

    WebElement wrapper = element("#cboxWrapper");

    Assert.assertEquals(wrapper.getCssValue("height"), "700px");
    Assert.assertEquals(wrapper.getCssValue("width"), "500px");

    closeLightbox();/*from   w ww  .  j a  v  a2s  .  com*/

    Dimension viewport = viewport();

    // fixed size in percent
    openLightbox(By.linkText("Rocky cliffs (Fixed size in percent)"));

    assertPixelValue(wrapper.getCssValue("width"), viewport.width * 0.5);
    assertPixelValue(wrapper.getCssValue("height"), viewport.height * 0.75);

    closeLightbox();
}

From source file:com.googlecode.ounit.selenium.CssHelper.java

License:Open Source License

public static String getFirstCssProperty(WebElement e, String[] props) {
    String rv = null;/*from   ww w .  j  av  a 2 s . com*/

    for (String prop : props) {
        // getCssValue is very browser specific
        rv = e.getCssValue(prop);
        if (rv != null && !rv.isEmpty() && !rv.equals("null"))
            break;
    }

    return rv;
}

From source file:com.htmlhifive.pitalium.it.screenshot.partialapge.KeepBodyStyleTest.java

License:Apache License

/**
 * body????????????isMove??<br>/*from   w  ww.  j ava2  s.  c om*/
 * ???????????<br>
 * IE711/FireFox/Chrome/Android 2.3, 4.0, 4.4/iOS 8.1<br>
 * ??body????????
 */
@Test
public void keepBodyStyleOffset() {
    driver.get(BASE_URL);

    final String position = "absolute";
    final String offsetLeft = "20px";
    final String offsetTop = "30px";

    // ????
    StringBuilder sb = new StringBuilder();
    sb.append("document.body.style.position = '");
    sb.append(position);
    sb.append("'; document.body.style.top = '");
    sb.append(offsetTop);
    sb.append("'; document.body.style.left = '");
    sb.append(offsetLeft);
    sb.append("';");
    System.out.println(sb.toString());
    driver.executeJavaScript(sb.toString());

    List<CompareTarget> targets = new ArrayList<CompareTarget>();
    targets.add(new CompareTarget(ScreenArea.of(SelectorType.ID, "about"), null, true));
    assertionView.assertView("CssSelector", targets);

    // ?body?????
    WebElement body = driver.findElement(By.tagName("body"));
    //body.getCssValue("position");
    assertThat(body.getCssValue("position"), is(position));
    assertThat(body.getCssValue("top"), is(offsetTop));
    assertThat(body.getCssValue("left"), is(offsetLeft));
}

From source file:com.htmlhifive.pitalium.it.screenshot.partialapge.KeepBodyStyleTest.java

License:Apache License

/**
 * body????????????isMove??<br>/*from  w  w  w . j  a  va  2s .  com*/
 * ???????????<br>
 * IE711/FireFox/Chrome/Android 2.3, 4.0, 4.4/iOS 8.1<br>
 * ??body????????
 */
@Test
public void keepBodyStyleMargin() {
    driver.get(BASE_URL);

    final String position = "absolute";
    final String marginWidth = "20px";

    // ????
    StringBuilder sb = new StringBuilder();
    sb.append("document.body.style.position = '");
    sb.append(position);
    sb.append("'; document.body.style.margin = '");
    sb.append(marginWidth);
    sb.append("';");
    System.out.println(sb.toString());
    driver.executeJavaScript(sb.toString());

    List<CompareTarget> targets = new ArrayList<CompareTarget>();
    targets.add(new CompareTarget(ScreenArea.of(SelectorType.ID, "about"), null, true));
    assertionView.assertView("CssSelector", targets);

    // ?body?????
    WebElement body = driver.findElement(By.tagName("body"));
    //body.getCssValue("position");
    assertThat(body.getCssValue("position"), is(position));
    assertThat(body.getCssValue("margin-top"), is(String.valueOf(marginWidth)));
    assertThat(body.getCssValue("margin-right"), is(String.valueOf(marginWidth)));
    assertThat(body.getCssValue("margin-bottom"), is(String.valueOf(marginWidth)));
    assertThat(body.getCssValue("margin-left"), is(String.valueOf(marginWidth)));
}

From source file:com.htmlhifive.pitalium.it.screenshot.partialapge.TakeFixedElementWithMoveOptionTest.java

License:Apache License

/**
 * ????????isMove??<br>/* w  w  w  . j  a  va2 s .co m*/
 * ???????????<br>
 * IE711/FireFox/Chrome/Android 2.3, 4.0, 4.4/iOS 8.1<br>
 * ???????????
 */
@Test
public void moveFixedElement() {
    driver.get(BASE_URL);

    final String position = "absolute";
    final String offsetTop = "30px";
    final String offsetLeft = "20px";

    // ????
    StringBuilder sb = new StringBuilder();
    sb.append("var about = document.getElementById('about');");
    sb.append("about.style.position = '");
    sb.append(position);
    sb.append("'; about.style.top = '");
    sb.append(offsetTop);
    sb.append("'; about.style.left = '");
    sb.append(offsetLeft);
    sb.append("';");
    driver.executeJavaScript(sb.toString());

    List<CompareTarget> targets = new ArrayList<CompareTarget>();
    targets.add(new CompareTarget(ScreenArea.of(SelectorType.ID, "about"), null, true));
    assertionView.assertView("CssSelector", targets);

    // ????????
    WebElement about = driver.findElement(By.id("about"));
    assertThat(about.getCssValue("position"), is(position));
    assertThat(about.getCssValue("top"), is(offsetTop));
    assertThat(about.getCssValue("left"), is(offsetLeft));
}

From source file:com.htmlhifive.pitalium.it.screenshot.partialapge.TakeHiddenPartTest.java

License:Apache License

/**
 * ?visibility: hidden??????????????<br>
 * IE711/FireFox/Chrome/Android 2.3, 4.0, 4.4/iOS 8.1<br>
 * ????????????()??????????<br>/*w  ww  .j a v  a 2 s  . co m*/
 * ????????????????
 */
@Test
public void takeHiddenPart() {
    driver.get(BASE_URL);
    List<CompareTarget> targets = new ArrayList<CompareTarget>();
    targets.add(new CompareTarget(ScreenArea.of(SelectorType.CSS_SELECTOR, "#about")));

    // ?????
    driver.executeJavaScript("document.getElementById('about').style.visibility = 'hidden';");
    assertionView.assertView("takeHiddenPart", targets);

    // ???????
    WebElement about = driver.findElement(By.id("about"));
    assertThat(about.getCssValue("visibility"), is("hidden"));

}

From source file:com.induscorp.prime.testing.ui.core.objects.DOMObjectValidator.java

License:Open Source License

/**
 * Return true only if first element is visible.
 * /* w  w w. ja  v a 2s .c  o m*/
 * @param numRetries
 * @return
 */
@Override
public boolean isVisible(int numRetries) {
    boolean elemVisible = false;
    WebElement webElem = null;
    for (int i = 0; i <= numRetries; i++) {
        try {
            webElem = browser.getSeleniumWebDriver().findElement(domObject.getLocatorAsBy());
            if (webElem != null && !"hidden".equals(webElem.getCssValue("visibility"))) {
                elemVisible = true;
                break;
            }
        } catch (Throwable th) {
            if (i == numRetries) {
                break;
            }
        }
        browser.waitForSeconds(2);
    }
    return elemVisible;
}

From source file:com.liferay.cucumber.selenium.WebDriverHelper.java

License:Open Source License

public static void assertCssValue(WebDriver webDriver, String locator, String cssAttribute, String cssValue)
        throws Exception {

    WebElement webElement = getWebElement(webDriver, locator);

    String actualCssValue = webElement.getCssValue(cssAttribute);

    if (!actualCssValue.equals(cssValue)) {
        throw new Exception("CSS Value " + actualCssValue + " does not match " + cssValue);
    }/*from   ww w  . ja  v a2  s .  co m*/
}

From source file:com.liferay.faces.test.showcase.inputtextarea.InputTextareaSizeTester.java

License:Open Source License

@Test
public void runInputTextareaSizeTest() throws Exception {

    BrowserDriver browserDriver = getBrowserDriver();
    navigateToUseCase(browserDriver, "inputTextarea", "size");

    // Test that the value submits successfully
    String text = "Hello World!";
    browserDriver.sendKeysToElement(textarea1Xpath, text);
    browserDriver.clickElementAndWaitForRerender(submitButton1Xpath);

    WaitingAsserter waitingAsserter = getWaitingAsserter();
    waitingAsserter.assertTextPresentInElement(text, modelValue1Xpath);
    waitingAsserter.assertElementDisplayed("//textarea[@cols='50'][@rows='6']");

    // Test that the value submits successfully
    browserDriver.sendKeysToElement(textarea2Xpath, text);
    browserDriver.clickElementAndWaitForRerender(submitButton2Xpath);
    waitingAsserter.assertTextPresentInElement(text, modelValue2Xpath);

    WebElement textarea2 = browserDriver.findElementByXpath(textarea2Xpath);
    String expectedWidth = "150px";
    String width = textarea2.getCssValue("width");
    Assert.assertEquals("Width of element " + textarea2 + " is not \"" + expectedWidth + "\". Instead it is \""
            + width + "\".", expectedWidth, width);

    String expectedHeight = "150px";
    String height = textarea2.getCssValue("height");
    Assert.assertEquals("Height of element " + textarea2 + " is not \"" + expectedHeight
            + "\". Instead it is \"" + height + "\".", expectedHeight, height);
}