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.
Create a new Java class file for the WebElementExtender.java
class, or you can use the class created in the previous recipe.
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; public class WebElementExtender { public static void highlightElement(WebElement element) { for (int i = 0; i < 5; i++) { WrapsDriver wrappedElement = (WrapsDriver) element; JavascriptExecutor driver...