Reputation: 117
I would like to know if someone found a way to call a function in the condition of the IF.
My goal is to do something like
${etat}= Set Variable If Page Should Contain Element xpath=//*[@id="${status}"] 3 OUV FER
The function Page Should Contain Element xpath=//*[@id="${status}"] 3
works well and if it fails if it does not exist. I just would like to know if this actual item exist or not, and depending on the state, do one thing or another. In my case, return the label OUV or FER depending on the current state.
Right now, this gives me an error:
Evaluating expression 'Page Should Contain Element' failed: SyntaxError: invalid syntax (<string>, line 1)
The doc of robotframework is not great and I can't find a way to make it.
I would like to do it using their functions and not a custom one, as I do not want to access to the browser using JS and check the element externally.
Thank you
Upvotes: 0
Views: 1808
Reputation: 1575
You should use "Run Keyword And Return Status" keyword to get the status of the keyword.
In below script, first line will get True, if the element exists.
${Status}= Run Keyword And Return Status Page Should Contain Element xpath=//*[@id="${status}"]
${etat}= Set Variable If '${Status}'=='True' OUV FER
Upvotes: 3