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.

#ThanksForReading

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

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.