retrieve background-color attribute

2,420 views
Skip to first unread message

Jacky Jedsada

unread,
Sep 23, 2014, 6:00:33 AM9/23/14
to robotframe...@googlegroups.com
Dear All:

Is there any keyword I could use to retrieve background-color from an element?
I tried

Get Element Attribute   id=table-row@Style
Get Element Attribute   id=table-row@background-color

without luck.

Suggestions would be appreciated.

Thanks!
Jacky

Kevin O.

unread,
Sep 23, 2014, 10:39:54 AM9/23/14
to robotframe...@googlegroups.com
People in the past have used the style attribute in JavaScript, but that only works for inline style or for computed style, there are cross-browser issues.
I looked and I cannot see any request for this functionality??
The Selenium API exposes functionality to check CSS style in a cross-browser way from a WebElement, but it is not exposed directly in Selenium2Library.
To work around, you can use Execute Javascript to return the WebElement you are interested in and go from there...

Try:
${elem}=    Execute Javascript    return document.getElementById('table-row');
${bg color}=    Call Method    ${elem}    value_of_css_property    background-color

${bg color} should end up as a unicode string with a value like "rgba(238, 238, 238, 1)"

Kevin

Kevin O.

unread,
Sep 23, 2014, 10:43:24 AM9/23/14
to robotframe...@googlegroups.com

Jacky Jedsada

unread,
Sep 24, 2014, 2:07:01 AM9/24/14
to robotframe...@googlegroups.com
Fantastic solution!

Where can I find out what other methods I am able to call for this object?

Thanks Kevin.

Jacky Jedsada

unread,
Sep 24, 2014, 5:10:56 AM9/24/14
to robotframe...@googlegroups.com

Shiva Prasad Adirala

unread,
May 19, 2018, 2:38:41 AM5/19/18
to robotframework-users
Get css value using javascript in robot framework. Link here
Reply all
Reply to author
Forward
0 new messages