Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

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

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...