Make Selenium Easy

How To Verify Text In Bold Using Selenium WebDriver

Recently, a guy asked me below question:

I need to verify title of an article is in bold. Article title has no <b> or <strong> tag. How to verify it now?

It was also new to me and learnt new thing that day. So I am sharing my knowledge here.

HTML provides two tags to make text bold:- b and strong.

In above case you can easily locate the text and get tag name. You can assert tag name as “b” or “strong”.

But CSS provides an attribute called “font-weight” which is more powerful. You can assign this to html element with values. You can make text normal, bold and bolder. Refer all possible values here.

If you have bold text using above css attribute, you need to retrieve this from element and assert as expected.

Sample HTML code:

Java Program:

In above example, I consider bold text but you can change it as per your requirement. If you are confused with how to get css value- Read this post.

In case of any doubt, suggestion or you find some mistake, feel free to let me know in comments.


Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

How To Verify Text In Bold Using Selenium WebDriver

by Amod Mahajan time to read: 2 min
%d bloggers like this: