How to get the css style of text-overflow in robot framework

后端 未结 2 1532
情话喂你
情话喂你 2020-12-22 02:51

How to get the css style of text-overflow in robot framework. For validating the ellipsis text.



        
相关标签:
2条回答
  • 2020-12-22 03:12

    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}
    
    0 讨论(0)
  • 2020-12-22 03:23

    in robot framework to get text you can use, this will store text in variable data

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

    this will give you data variable as 123456789123456789qwertyuiasdfghjklzxcvbnmasdfghjkqwertyuiasdfghjkzxcvbnmertyui

    for validation you can use

    for partial match use :

    Element Should Contain    locator    text_should_check_with
    

    for exact match use :

    Element Text Should Be    locator    text_should_check_with
    
    0 讨论(0)
提交回复
热议问题