Is it possible to set a background color of an element in selenium

I am using Selenium with Java, and I want to change a background color of an element on the screen. Is it possible?


Solution 1:

You can set it using javascript by using executescript

((JavascriptExecutor) driver).executeScript("document.getElementById('locatorid').style.backgroundColor = 'lightblue';");

There are several javascript functions if you need to locate it by classname or name

document.getElementsByName
document.getElementsByClassName

Hope this helps you....if u need more accurate answer...pls post the element html source