【问题标题】:Is there a way to check for loop exhausted without any item matched in robot framework?有没有办法检查在机器人框架中没有任何项目匹配的循环是否耗尽?
【发布时间】:2018-06-04 12:12:20
【问题描述】:
select msgbox by title and check
[Arguments]    ${title}    ${msg}
@{wins}    Get Window Handles
:FOR    ${win}    IN    @{wins}
\    Select Window    ${win}
\    ${current_win_title}    Get Title
\    run keyword if    "${current_win_title}" == "${title}"    run keywords    Element Text Should Be    contentTD    ${msg}
\    ...    AND    Exit For Loop

您好,我正在使用 SeleniumLibrary 和 robotsframework 测试网站,我需要通过窗口标题切换到特定窗口并检查窗口中的元素文本。

我的问题是在某些情况下所有窗口都不匹配 for 循环中的 if 条件并且循环已用尽,有没有办法检查这种情况并再次运行 for 循环或剂量机器人框架 for 循环有 else在这种情况下参与 for 循环?

【问题讨论】:

    标签: robotframework


    【解决方案1】:

    使用布尔变量是否满足条件,并在循环后检查其值:

    select msgbox by title and check
    [Arguments]    ${title}    ${msg}
    
    @{wins}    Get Window Handles
    ${found}=    Set Variable    ${False}
    :FOR    ${win}    IN    @{wins}
    \    Select Window    ${win}
    \    ${current_win_title}    Get Title
    \    ${found}=    Set Variable If     "${current_win_title}" == "${title}"    ${True}   ${False}
    \    run keyword if    ${found}    run keywords    Element Text Should Be    contentTD    ${msg}
    \    ...    AND    Exit For Loop
    
    Run Keyword If    not ${found}    Fail      The title was not found
    

    【讨论】:

      猜你喜欢
      • 2017-01-20
      • 1970-01-01
      • 2018-08-06
      • 2023-03-04
      • 2021-01-08
      • 2021-11-10
      • 2019-06-30
      • 1970-01-01
      • 2021-01-02
      相关资源
      最近更新 更多