Robotframework如果条件

时间:2015-10-28 05:56:48

标签: python-2.7 robotframework

当我运行此代码时,它显示${month}未找到且${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

1 个答案:

答案 0 :(得分:0)

${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}被解释为关键字而不是变量。