【问题标题】:How to verify that a word is Bold in selenium webdriver using Java?如何使用 Java 在 selenium webdriver 中验证一个单词是否为粗体?
【发布时间】:2016-07-21 07:12:58
【问题描述】:

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

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

【问题讨论】:

  • 无法验证是什么意思???有没有例外或其他什么?清除它
  • 并分享您的 HTML

标签: java selenium selenium-webdriver


【解决方案1】:

字体的粗体值使用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;

【讨论】:

    猜你喜欢
    • 2016-11-24
    • 1970-01-01
    • 1970-01-01
    • 2014-01-05
    • 2019-03-16
    • 1970-01-01
    • 1970-01-01
    • 2014-08-28
    • 1970-01-01
    相关资源
    最近更新 更多