'Capturing color of the text box before and after correct text is entered in the mandatory text fields for Lead in Salesforce Lightning

I'm trying to test new lead creation in Salesforce Lightning (Sales app). When correct text is entered into the shown mandatory field(s), the color around text box element changes (from white to light yellow) as shown in images below. I've tried capturing that via getCssValue(String attribute) method of selenium by passing 'background-color' and 'color' attributes, but to no avail. Please tell how to get this color change in Selenium before & after text is entered in mandatory field (e.g Last Name). Your help would be highly appreciated. (Note: Please overlook the red underline. I used it to highlight the field via Snipping Tool) enter image description here

enter image description here



Solution 1:[1]

You can get the element color(Background color of element) by:

element.getCssValue("background-color");

You can get the element text/caption color by:

element.getCssValue("color");

For example if you want to get the background and text color of "Sign in" button for LinkedIn, the code is as follows:

driver.get("https://www.linkedin.com/");
        String buttonColor = driver.findElement(By.name("submit")).getCssValue("background-color");
        String buttonTextColor = driver.findElement(By.name("submit")).getCssValue("color");
        System.out.println("Button color: " + buttonColor);
        System.out.println("Text color " + buttonTextColor);

do not forget to import

import org.openqa.selenium.support.Color;

The above code will return rgb value. If you want to convert to hex, you can go to getCssValue (Color) in Hex format in Selenium WebDriver

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Akzy