如何在机器人框架中获取 文本溢出 的CSS样式。用于验证省略号文本。
<td _ngcontent-c5="" class="fontStyle" data-placement="top" title="123456789123456789qwertyuiasdfghjklzxcvbnmasdfghjkqwertyuiasdfghjkzxcvbnmertyui"> 123456789123456789qwertyuiasdfghjklzxcvbnmasdfghjkqwertyuiasdfghjkzxcvbnmertyui </td>
更新:在当前的SeleniumLibrary(3.2+)中,有一个专用关键字:Get Element Attribute(获取元素属性)
SeleniumLibrary for Robot Framework不支持获取CSS属性的值。但是,value_of_css_propertySelenium Python模块中有一种方法可以完全做到这一点。
value_of_css_property
为了在元素上调用方法,Call Method可以在任何Robot变量或对象上使用standard关键字。在下面的示例中,我使用Google主页创建了一个自定义关键字和一些示例。应该根据您的目的轻松修改它们。
Call Method
*** 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}