如何在robot框架中获取text-overflow的css样式 [英] How to get the css style of text-overflow in robot framework
问题描述
如何在robot框架中获取text-overflow的css样式.用于验证省略号文本.
How to get the css style of text-overflow in robot framework. For validating the ellipsis text.
<td _ngcontent-c5="" class="fontStyle" data-placement="top" title="123456789123456789qwertyuiasdfghjklzxcvbnmasdfghjkqwertyuiasdfghjkzxcvbnmertyui"> 123456789123456789qwertyuiasdfghjklzxcvbnmasdfghjkqwertyuiasdfghjkzxcvbnmertyui </td>
推荐答案
更新:在当前的 SeleniumLibrary (3.2+) 中有一个专用关键字:获取元素属性
Update: in the current SeleniumLibrary (3.2+) there is a dedicated keyword: Get Element Attribute
SeleniumLibrary for Robot Framework 不支持获取 CSS 属性的值.但是,Selenium Python 模块中有一个名为 value_of_css_property
的方法可以做到这一点.
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.
为了在元素上调用方法,可以在任何机器人变量或对象上使用标准关键字Call Method
.在下面的示例中,我创建了一个自定义关键字和一些使用 Google 主页的示例.它们应该很容易根据您的目的进行修改.
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}
这篇关于如何在robot框架中获取text-overflow的css样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!