Selenium WebDriver get border color
How to get border color or other css values look in Computed there are all values that you can get:
getCssValue("border-bottom-color")
returns rgba(209, 219, 223, 1) and need to clear it (this will work for rgba and rgb):
String rgb[] = driver.findElement(By.name("login[email]")).getCssValue("border-bottom-color").replaceAll("(rgba)|(rgb)|(\\()|(\\s)|(\\))","").split(",");
Now our rgb is in array using this method to parse it
String hex = String.format("#%s%s%s", toBrowserHexValue(Integer.parseInt(rgb[0])), toBrowserHexValue(Integer.parseInt(rgb[1])), toBrowserHexValue(Integer.parseInt(rgb[2])));private static String toBrowserHexValue(int number) { StringBuilder builder = new StringBuilder(Integer.toHexString(number & 0xff)); while (builder.length() < 2) { builder.append("0"); } return builder.toString().toUpperCase(); }
From this rgba(209, 219, 223, 1) we got this #D1DBDF
There seems to be an issue with element.getCssValue("border-color") using a Firefox Driver. This is due to Shorthand CSS properties (e.g. margin, background, border) not been supported.
For Firefox you will need to enter
System.out.println("'"+element.getCssValue("border-top-color")+"'");
The code will print out 'rgba(207, 76, 53, 1)'
Using a ChromeDriver to get your value.
Your current code will print out 'rgb(207, 76, 53)'
To set the ChromeDriver you might need to add this line before you declare your driver
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver.exe");WebDriver driver=new ChromeDriver();
You can download the ChromeDriver from here http://chromedriver.storage.googleapis.com/index.html