To retrieve the background color of an element, use the following code:
element.getCssValue("background-color");
To retrieve the text or caption color of an element, use this code:
element.getCssValue("color");
For instance, if you wish to get the background and text colors of the "Sign in" button on LinkedIn, you can do so with the following code snippet:
driver.get("https://www.amazon.com/");
String buttonColor = driver.findElement(By.id("searchDropdownBox")).getCssValue("background-color");
String buttonTextColor = driver.findElement(By.id("searchDropdownBox")).getCssValue("color");
System.out.println("Button color: " + buttonColor);
System.out.println("Text color: " + buttonTextColor);