- Selenium WebDriver 3 Practical Guide
- Unmesh Gundecha Satya Avasarala
- 183字
- 2021-08-13 16:08:10
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
- 網(wǎng)絡教育學習指導
- Aptana Studio Beginner's Guide
- 物聯(lián)網(wǎng)安全(原書第2版)
- Building Django 2.0 Web Applications
- 物聯(lián)網(wǎng)檢驗檢測技術
- Learning QGIS 2.0
- 智慧城市中的移動互聯(lián)網(wǎng)技術
- 網(wǎng)管員必讀:網(wǎng)絡管理(第2版)
- CCNP TSHOOT(642-832)認證考試指南
- 物聯(lián)網(wǎng)長距離無線通信技術應用與開發(fā)
- 網(wǎng)絡環(huán)境中基于用戶視角的信息質(zhì)量評價研究
- 人人都該都懂的互聯(lián)網(wǎng)思維
- 異構蜂窩網(wǎng)絡關鍵理論與技術
- Guide to NoSQL with Azure Cosmos DB
- 小型局域網(wǎng)組建