Get color attribute from the styles table Get color attribute from the styles table selenium selenium

Get color attribute from the styles table


I don't have a C# environment to test it in, but something like this should work:

string js = "    window.document.defaultView.getComputedStyle(        window.document.getElementById('outercontainer'), null).            getPropertyValue('background-color');            ";string res = selenium.GetEval(js);

Now res will contain the rgba value of the background color. You will have to use Javascript since Selenium doesn't work on the computed styles, only on the styles defined in the HTML tags themselves.

I played with the linebreaks a bit to keep things readable: the js string can all be put on a single line.


Try with:

string rgbaColor = yourElement.GetCssValue("background-color");