gpt4 book ai didi

robotframework - 如何在 Robot Framework 中退出 for 循环

转载 作者:行者123 更新时间:2023-12-04 01:07:40 26 4
gpt4 key购买 nike

我从列表中选择一个随机值来对其执行一些操作,例如 Run Keyword If、Exit For Loop If、单击元素、等到页面包含等等。现在我无法在满足条件后退出 for 循环,但发生的事情是从为值 Batman 设置的开始条件开始。

已经尝试过 :break & Exit For Loop 关键字,但它们对我不起作用

@{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:旧语法(这也适用)
: FOR    ${value}    IN    @{Hero}
\ Do your stuff
\ Exit For Loop IF "${value}" == "${Batman}"
\ Do your stuff

关于robotframework - 如何在 Robot Framework 中退出 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56461983/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com