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

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
主站蜘蛛池模板: 微山县| 郴州市| 峨边| 定远县| 仲巴县| 临湘市| 长子县| 云浮市| 乌兰浩特市| 丰宁| 南岸区| 七台河市| 鹤峰县| 宜兴市| 平昌县| 安新县| 宜昌市| 正宁县| 土默特右旗| 项城市| 通渭县| 东兴市| 海口市| 梓潼县| 荆门市| 乌拉特前旗| 青河县| 本溪市| 山西省| 简阳市| 福鼎市| 朔州市| 乳源| 临潭县| 个旧市| 吉首市| 奉贤区| 黎城县| 会理县| 黎平县| 临高县|