英文:
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#
的人。
-
确定并将所需元素存储到变量中。您可能会使用下面其中一个 XPath 表达式来定位该元素
//div[text()='INFORMATIONBOLD']
或者:
//nobr[text()='INFORMATIONBOLD']
-
将字体粗细的 CSS 值存储到变量中,如下所示
var fontWeight = webelement.GetCssValue("font-weight");
-
如果 fontWeight 大于或等于 700 THEN "Its bold"
-
Else "its not bold"
英文:
Algorithm: I can only give you an algorithm as am not a c#
person.
- 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']
- Store the font-weight CSS value into a variable as below
var fontWeight = webelement.GetCssValue("font-weight");
- if fontWeight is greater than or equal to 700 THEN "Its bold"
- Else "its not bold"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论