How to Validate Field Color in Selenium WebDriver – Validation for Mandatory FIeld or Valid values

Hello Folks,

Color code may represents an information about field. Consider below scenarios:

  1. All mandatory field of a web form will have a yellow bottom color.

     2. If User does not enter proper value in a text box, color of text box will be converted in to red.

You can verify these functionalities easily in Manual testing. We must include these validation in out automation scripts as well to increase test coverage by automation scripts.

Generally color code to a web element is given using CSS Style which we can easily check while inspecting. See an example below:

  1. Inspect the web element.
  2. Check “Styles” tab at right hand side.
  3. Here you can check all css attribute applied on inspected web element.
  4. There you will see color codes on web element if applied by developer as per requirements.
  5. You just need to identify correct css attribute. For example: To check bottom color of field, we need “border-bottom-color” css property.
  6. Css property named “border-bottom-color” has an hex code as value which represents a color. You can convert this color in to RGB.

HTML Code:

<html>
   <head>
      <style>
         input{
         border-bottom-color: #ffddac;
         }
      </style>
   </head>
   <body>
      Email: <input type="email" id="email" placeholder="Email Address">
   </body>
</html>

 

JAVA Code:

Hope, this post will help you to increase test coverage of your automation scripts.
Use below website to convert hex code of color to RGB:

HEX to RGB

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappySelenium

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