- 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)絡云百問百答
- Building E-commerce Sites with VirtueMart Cookbook
- 從區(qū)塊鏈到Web3:構建未來互聯(lián)網(wǎng)生態(tài)
- Oracle SOA Suite 11g Performance Tuning Cookbook
- Proxmox High Availability
- Working with Legacy Systems
- 網(wǎng)絡環(huán)境中基于用戶視角的信息質量評價研究
- jQuery Mobile Web Development Essentials
- Learning Storm
- 深入理解OpenStack Neutron
- 5G+區(qū)塊鏈
- 深入理解Nginx:模塊開發(fā)與架構解析
- 計算機網(wǎng)絡技術
- 華為HCIA-Datacom認證指南
- 中國信息化年鑒2017