How to highlight elements Selenium Webdriver using JavaScript

In Automation, testing sometimes element highlighter plays very important role. It helps us to track our execution flow which step is being processed. Some tools like QTP, Sahi etc. you will get this inbuilt feature. For Selenium, we have to write small code, which simply highlight element based on our parameter values. let’s get started and see Highlight element Selenium using CSS values.


Highlight element Selenium


In Selenium, we can use JavascriptExecutor (interface) to execute Javascript code into webdriver.


I have published video on the same which covers the same.


In this post we, will execute Javascript which will highlight the element

Let’s implement the same this will highlight the user name field.

In above program it, will highlight username field. Now we can not write every time the same code to highlight element so we will create reuse method and when we have to highlight element we will call the method.


Create highlight element method for reuse


Complete program for Highlight element Selenium

You can also create a separate library for this and can you in other programs as well.

Try from your side and let me know if you finding some issue.

Please share with others as well. Keep visiting. Have a nice day 🙂


  1. Ajay