【问题标题】:Robotframework If conditionRobotframework If 条件
【发布时间】:2016-01-08 23:35:58
【问题描述】:

当我运行此代码时,它显示 ${month} not found 并且 ${month status} 正在返回 True

${month status}=    Run Keyword and Return Status    Element Should Be Visible    xpath=//div[@data-title='Cost for Month']
    Run Keyword If    '${month status}' == 'True'
    ...    ${month}=    Get Text    xpath=//div[@data-title='Cost for Month']    
    ...    Log    Dashboard is displaying ${month} Cost Usage for month Text
    ...    ELSE
    ...    Fail    Cost Dashboard is not displaying Cost Usage for month Text

【问题讨论】:

  • 请格式化您的代码块并为您的问题添加更多上下文
  • 为什么 Get Text 应该在这种情况下工作,您确定这是适合您场景的关键字吗?更多信息将帮助我们确定这一点,向我们展示 html 的 sn-p。

标签: python-2.7 robotframework


【解决方案1】:
${month status}=    Run Keyword and Return Status    Element Should Be Visible    xpath=//div[@data-title='Cost for Month']
${month}=    Run Keyword If    '${month status}' == 'True'  Get Text    xpath=//div[@data-title='Cost for Month']    
Run Keyword If    '${month status}' == 'True'  Log    Dashboard is displaying ${month} Cost Usage for month Text

Run Keyword If    '${month status}' == 'False'  Fail    Cost Dashboard is not displaying Cost Usage for month Text

有点粗略的解决方案,但我们也遇到了这种情况,并使用上面的修复方法解决了它。

我认为您的代码失败了,因为 ${month} 被解释为关键字而不是变量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-08
    • 2020-08-20
    • 1970-01-01
    相关资源
    最近更新 更多