O'Reilly logo

Selenium Testing Tools Cookbook by Unmesh Gundecha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing an extension for the WebElement object to highlight elements

During test execution, there is no way to highlight an element. This will help us to see what is actually going on in the browser. This method will slow down the tests a bit, but sometimes it's a useful way to debug tests.

In this recipe, we will create an extension for WebElement and provide the highlight Elements() method at runtime.

Getting ready

Create a new Java class file for the WebElementExtender.java class, or you can use the class created in the previous recipe.

How to do it...

Add the highlightElement() method to the WebElementExtender class, as follows:

import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebElement; import org.openqa.selenium.internal.WrapsDriver; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required