Below is the code I am using to highlight the element.
public static void highLightElement(WebDriver driver, WebElement element)
{
JavascriptExecutor js=(JavascriptExecutor)driver;
js.executeScript("arguments[0].setAttribute('style', 'background: yellow; border: 2px solid red;');", element);
try
{
Thread.sleep(1000);
}
catch (InterruptedException e) {
System.out.println(e.getMessage());
}
js.executeScript("arguments[0].setAttribute('style','border: solid 2px white');", element);
}
}
Now I am calling this reusable to my code. But I want to use it in such a way that it will highlight elements only if I use some kind of flag (true). My motto is that it will not highlight element in normal execution but if I flag it I can see the highlighted element while debugging.