2

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

justadev
  • 1,168
  • 1
  • 17
  • 32

3 Answers3

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 + "");

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