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

♀尐吖头ヾ 提交于 2019-12-29 09:26:10

问题


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>

回答1:


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}



回答2:


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


来源:https://stackoverflow.com/questions/53001999/how-to-get-the-css-style-of-text-overflow-in-robot-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!