如何使用Selenium检查文本是否以粗体显示

huangapple go评论73阅读模式
英文:

How to get the if the text is displayed on bold with selenium

问题

我必须使用Selenium C#验证INFORMATIONBOLD是否以粗体样式显示,我已经使用XPath选择器找到了样式:

//style[@type='text/css']

但我无法找到一种方法来验证之前使用的特定类是否以粗体样式显示。

英文:

I have a pdf document like this:

\<div class=**"cs6C976429"** style="width:671px;height:18px;line-height:17px;margin-top:98px;margin-left:94px;position:absolute;text-align:left;vertical-align:top;"\>
\<nobr\>INFORMATIONBOLD\</nobr\>\</div\>
\<style type="text/css"\>
.cs85480F5E {color:#000000 !important;background-color:transparent !important;border-left-style: none !important;border-top-style: none !important;border-right-style: none !important;border-bottom-style: none !important;font-family:'Times New Roman' !important; font-size:13px !important; font-weight:normal !important; font-style:normal !important;  !important;}
.cs8B56BD64 {color:#000000 !important;background-color:transparent !important;border-left-style: none !important;border-top-style: none !important;border-right-style: none !important;border-bottom-style: none !important;font-family:'Times New Roman' !important; font-size:15px !important; font-weight:bold !important; font-style:normal !important;  !important;}
**.cs6C976429** {color:#000000 !important;background-color:transparent !important;border-left-style: none !important;border-top-style: none !important;border-right-style: none !important;border-bottom-style: none !important;font-family:'Times New Roman' !important; font-size:15px !important; **font-weight:bold** !important; font-style:normal !important; padding-left:2px !important;}
.cs354AAA62 {color:#808080 !important;background-color:transparent !important;border-left-style: none !important;border-top-style: none !important;border-right-style: none !important;border-bottom-style: none !important;font-family:'Times New Roman' !important; font-size:16px !important; font-weight:bold !important; font-style:normal !important; padding-left:2px !important;padding-right:2px !important;}
\</style\>

I have to validate the INFORMATIONBOLD is in bold style by selenium, I found the style with the Xpath selector:

\//style\[@type='text/css'\] 

I am not able to find a way to validate the specific class used before is with the bold style with Selenium C#

答案1

得分: 0

算法: 我只能给你一个算法,因为我不是一个 c# 的人。

  1. 确定并将所需元素存储到变量中。您可能会使用下面其中一个 XPath 表达式来定位该元素
    //div[text()='INFORMATIONBOLD']
    或者:
    //nobr[text()='INFORMATIONBOLD']

  2. 将字体粗细的 CSS 值存储到变量中,如下所示
    var fontWeight = webelement.GetCssValue("font-weight");

  3. 如果 fontWeight 大于或等于 700 THEN "Its bold"

  4. Else "its not bold"

英文:

Algorithm: I can only give you an algorithm as am not a c# person.

  1. Identify and store the desired element into a variable. You may probably use one of the below XPath expression to locate the element
//div[text()='INFORMATIONBOLD']

or:

//nobr[text()='INFORMATIONBOLD']
  1. Store the font-weight CSS value into a variable as below
var fontWeight = webelement.GetCssValue("font-weight");
  1. if fontWeight is greater than or equal to 700 THEN "Its bold"
  2. Else "its not bold"

huangapple
  • 本文由 发表于 2023年6月5日 23:12:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76407808.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定