Reading font properties using .getCssValue() method

Sometime you may require to get font size, font color, font family, font background color etc. during webdriver test case execution. Selenium webdriver has built in method to perform these operations. 


Reading font properties using .getCssValue() method

Please see the following code illustrating how to use .getCssValue() Method
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
//WebElement
WebElement text = driver.findElement(By.id("SampleText"));

//Read font-size property
String fontSize = text.getCssValue("font-size");

//Read color property and print It In console.
String fontColor = text.getCssValue("color");

//Read font-family property and print It In console.
String fontFamily = text.getCssValue("font-family");

//Read text-align property and print It In console.
String fonttxtAlign = text.getCssValue("text-align");

//To get background color
String bgcolor = text.getCssValue("background-color");

//To check if text is underlined or not
String textdecoration = text.getCssValue("text-decoration");

<-- Previous || Next -->

No comments:

Post a Comment