Indrajit
Indrajit

Reputation: 331

How to verify that a word is Bold in selenium webdriver using Java?

I have a web application.I have a scenario that a search term becomes bold in some pages so i need to verify whether the search term is Bold or not. I have tried the following code but i am not able to verify:

String colour = driver.findElement(By.className("classname")).getCssValue("color");
if(colour.contains("rgba(46,46,46,1)"))
System.out.println("Term is Bold");
else
System.out.println("Term is not  Bold");

Upvotes: 0

Views: 2203

Answers (1)

raphaëλ
raphaëλ

Reputation: 6523

The bold value of a font is expressed using the font-weight CSS property

String fontWeight = driver.findElement(By.className("classname"))
                              .getCssValue("font-weight");

boolean isBold = "bold".equals(fontWeight) || "bolder".equals(fontWeight) || Integer.parseInt(fontWeight) >= 700;

Upvotes: 1

Related Questions