如何使用Java在Selenium Webdriver中验证单词是否为粗体?

问题描述:

我有一个Web应用程序.我有一个场景,搜索词在某些页面中变为粗体,因此我需要验证搜索词是否为粗体. 我已经尝试了以下代码,但无法验证:

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");

使用font-weight CSS属性

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

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