官术网_书友最值得收藏!

The getCssValue() method

The getCssValue method can be called on all the WebElements. This method is used to fetch a CSS property value from a WebElement. CSS properties can be font-family, background-color, color, and so on. This is useful when you want to validate the CSS styles that are applied to your WebElements through your test scripts. The API syntax for the getCssValue() method is as follows:

java.lang.String getCssValue(java.lang.String propertyName)

In the preceding code, the input parameter is the String value of the CSS property name, and the return type is the value assigned to that property name.

The following is the code example to retrieve font-family of the text from the Search box:    

@Test
public void elementGetCssValueExample() {
WebElement searchBox = driver.findElement(By.name("q"));
System.out.println("Font of the box is: "
+ searchBox.getCssValue("font-family"));
}

The preceding code uses the getCssValue() method to find font-family of the text visible in the Search box. The output of the method is shown here:

Font of the box is: Raleway, "Helvetica Neue", Verdana, Arial, sans-serif
主站蜘蛛池模板: 怀柔区| 馆陶县| 桓台县| 阿拉善右旗| 揭东县| 龙南县| 衢州市| 勃利县| 渭南市| 信阳市| 呼玛县| 新乡县| 北票市| 镇雄县| 太仆寺旗| 灵宝市| 苍南县| 大连市| 嘉兴市| 长白| 沧州市| 潢川县| 通榆县| 义马市| 县级市| 兰溪市| 绍兴县| 西华县| 铜陵市| 荣成市| 和硕县| 治多县| 松桃| 探索| 九龙城区| 永寿县| 壤塘县| 达孜县| 南召县| 黄骅市| 平塘县|