I want get value from a Keyword by using else if.
Example:
String text = ""
If variable > 5
text = "one";
else if variable <5
text = "two";
else
text = "three";
In Robot Framework
I use the code
${txt} Set Variable
${txt}= Run Keyword If ${length} > 5 Some Keyword
\ ELSE IF ${length} < 5 Some Keyword
\ ELSE Some Keyword
Log ${txt}
ERROR !!!
In Keyword ELSE IF ; Keyword name cannot be empty
END Use Run Keyword If in Robot Framework Run Keyword If ${True} Log This line IS executed. Run Keyword If ${False} Log This line is NOT executed. Use Run Keyword Unless in Robot Framework Run Keyword Unless ${True} Log This line is NOT executed. Run Keyword Unless ${False} Log This line IS executed.
You can do a couple of things. The first is to create a new keyword that calls all the other keywords, and then call that from Run keyword if . This might be the most readable solution, but at the expense of having to write and document another keyword. Show activity on this post.
By locating the element using xpath, I assume that you're using Sselenium2Library . In that lib there is a keyword named: Page Should Contain Element which requires an argument, which is a selector , for example the xpath that defines your element. The keyword failes, if the page does not contain the specified element.
Just add THREE DOTS (...) in first cell before ELSE IF keyword
${txt} Set Variable
${txt}= Run Keyword If ${lenght} > 5 Some Keyword
... ELSE IF ${lenght} < 5 Some Keyword
... ELSE Some Keyword
Log ${txt}
An alternate way to code this with Robot Framework's version of a switch statement is:
*** Variables ***
String ${text} = ""
*** Keywords ***
${text} = Set Variable If
... ${variable} > 5 one
... ${variable} < 5 two
... ${variable} = 5 three
There may be other ways using Run Keyword If and Run Keyword Unless.
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