Get color attribute from the styles table

微笑、不失礼 提交于 2019-11-28 13:52:06

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");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!