【问题标题】:How to get the css style of text-overflow in robot framework如何在机器人框架中获取文本溢出的css样式
【发布时间】:2019-03-30 19:36:43
【问题描述】:

如何在robot框架中获取text-overflow的css样式。用于验证省略号文本。

<td _ngcontent-c5="" class="fontStyle" data-placement="top" title="123456789123456789qwertyuiasdfghjklzxcvbnmasdfghjkqwertyuiasdfghjkzxcvbnmertyui"> 123456789123456789qwertyuiasdfghjklzxcvbnmasdfghjkqwertyuiasdfghjkzxcvbnmertyui </td>

【问题讨论】:

    标签: selenium robotframework


    【解决方案1】:

    更新:在当前的 SeleniumLibrary (3.2+) 中有一个专门的关键字:Get Element Attribute


    SeleniumLibrary for Robot Framework 不支持获取 CSS 属性的值。但是,Selenium Python 模块中有一个名为 value_of_css_property 的方法可以做到这一点。

    为了在元素上调用方法,标准关键字Call Method 可用于任何机器人变量或对象。在下面的示例中,我使用 Google 主页创建了一个自定义关键字和一些示例。它们应该很容易根据您的目的进行修改。

    *** 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}
    

    【讨论】:

    • 嗨@A。 kootstra 要验证字体大小/粗体/斜体/文本颜色等文本样式,在机器人框架中应该查看哪些关键字/库?
    • 这些可以是元素的属性,或者更可能是 CSS 属性。如果它们是后者,则可以使用此关键字来检查它们的特定值。看看你的浏览器开发工具来检查这些。如果您想了解更多信息,请创建一个新问题,因为这里不应该讨论这个问题。
    • 请为此创建一个新问题。它超出了原始问题的范围。
    【解决方案2】:

    在机器人框架中获取可以使用的文本, 这会将文本存储在变量data

    ${data}    Get Text    xpath=*//td[@class='fontStyle' and @data-placement='top']
    

    这会给你data变量123456789123456789qwertyuiasdfghjklzxcvbnmasdfghjkqwertyuiasdfghjkzxcvbnmertyui

    你可以使用验证

    部分匹配使用:

    Element Should Contain    locator    text_should_check_with
    

    精确匹配使用:

    Element Text Should Be    locator    text_should_check_with
    

    【讨论】:

    • 我需要检查显示的文本是省略号。通过获取文本溢出的css样式:省略号
    猜你喜欢
    • 2014-08-21
    • 2015-12-31
    • 1970-01-01
    • 2020-01-26
    • 1970-01-01
    • 1970-01-01
    • 2021-12-16
    • 2013-11-18
    • 2019-07-18
    相关资源
    最近更新 更多