I am using Selenium with Java, and I want to change a background color of an element on the screen. Is it possible?
Asked
Active
Viewed 9,466 times
3 Answers
4
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

Vicky
- 2,999
- 2
- 21
- 36
0
Try This
((JavascriptExecutor) WebDriverRunner.getWebDriver()).executeScript("document.querySelector("locatoe").innerText=" + value + "");

Pankaj Kumar
- 1
- 1
0
If you have the element e.g. in Python, you can also
driver.execute_script("arguments[0].style.backgroundColor = 'lightblue';", element)
This probabaly works similarly in Java.

serv-inc
- 35,772
- 9
- 166
- 188