Tips for detecting if text appears in bold on a webpage using Selenium

I came across a pdf document with the following content:

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

My task is to confirm whether INFORMATIONBOLD appears in bold using Selenium, and I have identified the style using the Xpath selector:

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

However, I am currently struggling to determine how to verify that the specific class used previously is indeed displayed in bold style with Selenium in C#.

Answer №1

Strategy: Since I am not proficient in c#, I will provide you with a strategic plan instead of a specific algorithm.

  1. First step is to identify and save the desired element in a variable. You can try using one of the XPath expressions below to find the element
//div[text()='INFORMATIONBOLD']

or:

//nobr[text()='INFORMATIONBOLD']
  1. Save the font-weight CSS value in a variable like this:
var fontWeight = webelement.GetCssValue("font-weight");
  1. If the font-weight is equal to or greater than 700, then it means "Its bold"
  2. Otherwise, it means "its not bold"

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A system of Windows timers for efficient task scheduling in a service

At my current internship, I inherited a Windows service created by a previous intern. This service monitors an archive and sends alerts via emails and pop-ups if any recorded values fall outside of a certain range. Currently, it checks the archive every 30 ...

The display:flex property with justify-content:space-around is malfunctioning in React and causing issues

I've been trying to troubleshoot the issue with my header, but so far I haven't found a solution. Could you please take a look at my code first? // Code simplified for clarity, no need to worry about variables const Header = () => { return ...

What is the best way to place content in a single div without it being divided into several separate boxes

Here is my code snippet: <div class="col-md-9"> <div id="statbox"> {% for obj in product_type %} {% for obj1 in vastu %} <script type="text/javascript"&g ...

What could be causing the hover effect to malfunction in this code snippet?

I have been working on creating a hover effect for a list of items where an underline emerges from the center. While I have done something similar in the past, there seems to be an issue preventing it from working properly this time. I have included the HT ...

The footer menu fails to glide upwards

I designed a top menu for my website that includes 2 key features: Sticky navigation bar when scrolling Slide toggle navbar You can view the demo here: JSBIN However, I am facing 2 issues: When the page is at the top and the menu is in its default pos ...

Linking a Wordpress submenu to a specific section of a page

I am utilizing a Wordpress menu to act as the primary navigation for my website. Each main item in this menu is a Page Type that redirects to other existing pages, with one of them containing submenus made up of custom links. These custom links' URLs ...

Animating CSS using JavaScript

Recently diving into the world of JavaScript, I've taken on the challenge of creating an analog clock. I began by crafting the second hand using CSS but now I'm eager to transition it to Javascript without relying on jQuery or any other JS framew ...

Using numerous background images can lead to issues in Safari browser

Currently experimenting with styling the body element using two images. background: url(bg2.png) repeat-x, url(bg1.png) repeat; An issue arises in Safari where it reports an error in the console, stating that it cannot locate the image file specified at ...

CSS - Help! Seeing different results on Internet Explorer

I'm currently handling an OSCommerce website, and I'm trying to figure out why this issue is occurring. You can view the website at this link: The layout looks completely different on Internet Explorer, and I'm puzzled as everything should ...

Fatal error in CodeIgniter occurring while invoking CSS less functions

Whenever I try to execute this function, I encounter the following error message: "Fatal error: Uncaught exception 'Exception' with message 'load error: failed to find test.less' in C:\xampp\htdocs\project\applic ...

Having trouble choosing an option from the react-select dropdown in Robotframework

Within this dropdown menu labeled "sampleType," you will find various options such as "AB1, AB2, .. AB6." Upon manual selection of the dropdown, AB1 is initially chosen. It is necessary to choose other values within the range of AB2-AB6 based on user inp ...

The function fromEvent is throwing an error stating that the property does not exist on the type 'Event'

I'm attempting to adjust the position of an element based on the cursor's location. Here is the code I am currently using: this.ngZone.runOutsideAngular(() => { fromEvent(window, 'mousemove').pipe( filter(() => this.hove ...

Using Selenium RC with Hudson

Looking to integrate Selenium into Hudson and run a test using a .dll written in C# - is there a way to do this? Appreciate any guidance or suggestions. Thanks! ...

Need a guide to identify HTML elements with a particular attribute?

I attempted to find this information online, but I wasn't successful. Suppose I am interested in knowing all the HTML elements that contain a "background" attribute. I'm aware that some web browsers may not support certain elements. Off the top ...

Is there a way to prevent my <div> from scrolling when the mouse hovers over it?

I currently have a div that is set to scroll infinitely using JavaScript: <script language="javascript"> i = 0 var speed = 1 function scroll() { i = i + speed var div = document.getElementById("content") div.scrol ...

Removing the dividing line between columns in an Antd table: A simple step-by-step guide

Do you notice the lines dividing each table column heading in the image? I want to get rid of these lines from the table. The table component I am using is Antd table. https://ant.design/components/table#examples https://i.stack.imgur.com/Npx5G.png ...

Utilize the display property with grid to effortlessly expand a block to occupy the entire width

I am currently exploring the grid system and I have a specific challenge. I would like the third block to expand to its full width without the need for extra classes. Can this be achieved using only internal CSS? .grid { margin: 36px auto; height: ...

Fixed navigation menu at the top of the screen

Can anyone help me with my navbar issue? I want it to stay on top of the page, but there's a huge gap between the top of the page and the nav bar. I've tried running a JS file, but it doesn't seem to fix the problem. Any ideas on how to make ...

Firebug displays the class name and location twice in the right panel

When examining a div labeled with .mlm-clearfix, I noticed that Firebug was displaying this class name and its URL twice in the right panel. The style declarations given for the Easy Clear Method in relation to this class are as follows: .mlm-clearfix:bef ...

Inquiring about the rationale behind using `jquery.ui.all.css` specifically

I'm curious about the impact of jquery.ui.all.css on Tabs As soon as I remove it, <link rel="stylesheet" href="jquery/dev/themes/base/jquery.ui.all.css"> My tabs stop functioning. Here's my query: What exactly does the jquery.ui.all.cs ...