Highlight an element in selenium

While performing a user operation such as click, selecting a dropdown on UI the highlighting an element help us identified the element on the screen while debugging in case of an error.

One can highlight an element on the UI using the Javascript code which can be executed using a selenium javascript executor. The below method will help you highlight an element while performing an operation.

	 * Function to highlight the element on  current page
	 * @param by The {@link WebDriver} locator used to identify the element

	public void highlightElement(WebElement ele) throws InterruptedException{
		try	{
			//Creating JavaScriptExecuter Interface
			JavascriptExecutor executor = (JavascriptExecutor) driver;
			for (int i = 0; i < 1; i++) {
				//Execute java script			
				executor.executeScript("arguments[0].style.border='7px groove green'", ele);
				executor.executeScript("arguments[0].style.border=''", ele);			
		}	catch (Exception e) {
			System.out.println("Exception - "+e.getMessage());