Robotframework 机器人框架中如何退出for循环

Robotframework 机器人框架中如何退出for循环,robotframework,Robotframework,我从列表中选择一个随机值,对其执行一些操作,如运行关键字If、退出循环If、单击元素、等待直到页面包含和全部。现在我不能在满足条件后退出for循环,但是现在发生的是,从为值Batman设置的开始条件开始 已经尝试过:循环关键字的中断和退出,但对我来说不起作用 @{Hero} Batman Superman Ironman View All Details of Superhero ${value} = Evaluate random.choice($Hero) random

我从列表中选择一个随机值,对其执行一些操作,如运行关键字If、退出循环If、单击元素、等待直到页面包含和全部。现在我不能在满足条件后退出for循环,但是现在发生的是,从为值Batman设置的开始条件开始

已经尝试过:循环关键字的中断和退出,但对我来说不起作用

@{Hero}  Batman  Superman  Ironman

View All Details of Superhero
 ${value} =  Evaluate  random.choice($Hero)  random
    input text  ${SEARCH_BAR}  ${value}
    log to console  \nvalue: ${value}
    click element  ${SEARCH_BUTTON}

    Run Keyword If  '${value}' == 'Batman'  click element  ${P1}
    ...  ELSE IF  '${value}' == 'Superman'  click element  ${P2}
    ...  ELSE IF  '${value}' == 'Ironman'  click element  ${P3}
    ...  ELSE  log to console  condition didn't met

    :For  ${value}  IN  @{Hero}
        \  Log    ${value}
        \  Run Keyword If  '${value}' == 'Batman'  sleep  5s
        \  EXIT FOR LOOP IF  '${value}' == 'Batman'
        \  click element  //*[@href='#external']
        \  click element  ${BASIC_INFO}
        \  wait until page contains  Summary
        \  click element  ${RELATIONSHIP}
        @{expected_relationship_result}  create list  Catwoman  Robin
        list should contain value  @{expected_relationship_result}
        \  Log  condition didn't met

        \  Run Keyword If  '${value}' == 'Superman'  click element
        \  click element  //*[@href='#external']
        \  click element  ${BASIC_INFO}
        \  wait until page contains  Summary
        \  click element  ${RELATIONSHIP}
        @{expected_relationship_result}  create list  Wonderwomen  Lois Lane
        list should contain value  @{expected_relationship_result}  
        \  Log  condition didn't met

        \  Run Keyword If  '${value}' == 'Ironman'  sleep  5s  
        \  EXIT FOR LOOP IF  '${value}' == 'Ironman'
        \  click element  //*[@href='#external']  
        \  click element  ${BASIC_INFO}
        \  wait until page contains  Summary
        \  click element  ${RELATIONSHIP}
        @{expected_relationship_result}  create list  Wonderwomen  Lois Lane
        list should contain value  @{expected_relationship_result}
        \  Log  condition didn't met


I'm not able to figure out when the condition is already been met then why Exit For Loop If is not working.
解决方案1:

FOR    ${value}    IN    @{Hero}
    Do your stuff
    Exit For Loop IF    "${value}" == "${Batman}"
    Do your stuff
END
你能试试上面的语法吗。这是最新的for循环语法。它为我工作,也应该为你工作。 使用SeleniumLibrary最新版本

解决方案2:旧语法(这也适用)


“\”是从robot 3.2中贬值的。您可以添加正在发生的事情的控制台输出吗?
: FOR    ${value}    IN    @{Hero}
\    Do your stuff
\    Exit For Loop IF    "${value}" == "${Batman}"
\    Do your stuff