search

Home  >  Q&A  >  body text

How to get whether text is in bold using selenium

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 had to verify through selenium that the INFORMATIONBOLD was a bold style, which I found using the Xpath selector:

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

I can't find a way to validate a specific class before bold style using Selenium C

#
P粉147045274P粉147045274248 days ago335

reply all(1)I'll reply

  • P粉476883986

    P粉4768839862024-03-23 00:06:29

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

    1. Identify the required element and store it into a variable. You might use one of the following XPath expressions to locate elements
    //div[text()='INFORMATIONBOLD']

    or:

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

    reply
    0
  • Cancelreply