Update: in the current SeleniumLibrary (3.2+) there is a dedicated keyword: Get Element Attribute
Getting a value of a CSS property is not supported in the SeleniumLibrary for Robot Framework. However, there is a method called value_of_css_property
in the Selenium Python module that does exactly that.
In order to call a method on an element the standard keyword Call Method
can be used on any Robot variable or object. In the below example I created a custom keyword and some examples using the Google main page. They should be easily modified for your purpose.
*** Settings ***
Library SeleniumLibrary
Suite Teardown Close All Browsers
*** Test Cases ***
TC
Open Browser http://www.google.com Chrome
# a CSS property from the element.
${element_prop}= Get CSS Property Value id=SIvCob line-height
Should Be Equal As Strings ${element_prop} 28px
# a CSS property inherited from the <body> tag.
${body_prop}= Get CSS Property Value id=SIvCob font-family
Should Be Equal As Strings ${body_prop} arial, sans-serif
*** Keywords ***
Get CSS Property Value
[Documentation]
... Get the CSS property value of an Element.
...
... This keyword retrieves the CSS property value of an element. The element
... is retrieved using the locator.
...
... Arguments:
... - locator (string) any Selenium Library supported locator xpath/css/id etc.
... - property_name (string) the name of the css property for which the value is returned.
...
... Returns (string) returns the string value of the given css attribute or fails.
...
[Arguments] ${locator} ${attribute name}
${css}= Get WebElement ${locator}
${prop_val}= Call Method ${css} value_of_css_property ${attribute name}
[Return] ${prop_val}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…