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

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
主站蜘蛛池模板: 南阳市| 宜黄县| 潼关县| 南宁市| 洪江市| 成都市| 牟定县| 稻城县| 修文县| 宿州市| 南皮县| 大宁县| 华宁县| 衡南县| 凤台县| 巴彦淖尔市| 三门县| 滦平县| 石嘴山市| 保山市| 阿拉尔市| 连平县| 彰化县| 渝北区| 镶黄旗| 辽阳县| 伊通| 芒康县| 深泽县| 德惠市| 儋州市| 凌源市| 保德县| 准格尔旗| 博兴县| 唐河县| 江西省| 自贡市| 兴仁县| 合阳县| 北海市|