I'm choosing a random value from a list to perform some actions over it like Run Keyword If, Exit For Loop If, click element, wait untill page contains and all. Now I'm not able to exit the for loop after the condition is being met but what's happening is that is starts from the beginning conditions that are set for value Batman.
Already tried :break & Exit For Loop keywords but they didn't work out for me
@{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.
Solution 1:
FOR ${value} IN @{Hero}
Do your stuff
Exit For Loop IF "${value}" == "${Batman}"
Do your stuff
END
Can you try above syntax. This is latest for loop syntax. Its working for me and should work for you too. Use SeleniumLibrary latest version.
Solution 2: Old Syntax(this will also work)
: FOR ${value} IN @{Hero}
\ Do your stuff
\ Exit For Loop IF "${value}" == "${Batman}"
\ Do your stuff
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With