如何使用 selenium 获取文本是否以粗体显示
P粉147045274
P粉147045274 2024-03-22 10:52:43
[CSS3讨论组]

我有一个这样的pdf文档:

\<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\>

我必须通过 selenium 验证 INFORMATIONBOLD 是否为粗体样式,我使用 Xpath 选择器找到了该样式:

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

我无法找到一种方法来验证之前使用 Selenium C# 的粗体样式的特定类

P粉147045274
P粉147045274

全部回复(1)
P粉476883986

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

  1. 识别所需元素并将其存储到变量中。您可能会使用以下 XPath 表达式之一来定位元素
//div[text()='INFORMATIONBOLD']

或者:

//nobr[text()='INFORMATIONBOLD']
  1. 将 font-weight CSS 值存储到变量中,如下所示
var fontWeight = webelement.GetCssValue("font-weight");
  1. 如果 fontWeight 大于或等于 700 THEN “它是粗体”
  2. 否则“它不是粗体”
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号