【问题标题】:Get Element Attribute in robot framework在机器人框架中获取元素属性
【发布时间】:2016-10-24 05:22:20
【问题描述】:

你好如何在机器人框架中使用获取元素属性?在教学中我有 元素属性的返回值。

attribute_locator 由元素定位器后跟@符号和属性名称组成,例如element_id@class

我有这个xpath=${check_radio_xpath}@class 这是正确的方法吗? 其中${check_radio_xpath} = md-radio-11

我得到这个错误:

${ischecked} = Selenium2Library . Get Element Attribute xpath=${check_radio_xpath}@class

Documentation:
Return value of element attribute.

TRACE   Arguments: [ 'xpath=md-radio-11@class' ]        
DEBUG   Finished Request    
FAIL    ValueError: Element 'xpath=md-radio-11' not found.

【问题讨论】:

  • 请编辑问题并格式化。

标签: robotframework


【解决方案1】:

我认为你很接近。请尝试更好地格式化您的问题,我快速拍摄,因为您的问题难以阅读。结果会得到社区更多更好的帮助

${RADIO_XPATH}    //*[@id="${check_radio_xpath}"]
${CLASS}=    Selenium2Library.Get Element Attribute    ${check_radio_xpath}@class

【讨论】:

  • 所以这是您的问题,它解决了,还是您通过其他方式解决了?如果我的回答是正确的,请采纳。如果您以不同的方式解决它,请回答您自己的问题。
【解决方案2】:

<div><label for="foo"></label></div> 的示例

${for_value}=   Get Element Attribute  xpath=//div/label  for
Log To Console  ${for_value}

控制台结果是:

【讨论】:

    【解决方案3】:

    这个 sn-p 对我有用:

    Get Line Numbers And Verify
        ${line_number1}=    Get Element Attribute   //*[@id="file-keywords-txt-L1"] data-line-number
        Log To Console  ${line_number1}
        ${line_number2}=    Get Element Attribute   //*[@id="file-keywords-txt-L2"] data-line-number
        Log To Console  ${line_number2}
        Verify in order of ${line_number1} and ${line_number2} is true
    

    重要的是关键字之间的空格/制表符是正确的,否则它不会被识别为所谓的关键字。

    【讨论】:

      【解决方案4】:

      非常感谢,我想检查页面源中的 meta noindex 内容。

      我用过这个。

      ${content}  Get Element Attribute   xpath=//meta[@name="robots"]@content
      should be equal as strings  ${content}  noindex,follow
      

      【讨论】:

        【解决方案5】:

        如果你有 selenium 库,你可以同时使用 XPath 和 CSS 选择器

        ${title}=  Get Element Attribute  ${xpath}    attribute=title
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-05-04
          • 1970-01-01
          • 2021-05-14
          • 2021-12-25
          • 2015-11-11
          • 2020-12-07
          相关资源
          最近更新 更多