Hi, as I want to eliminate code duplication I am trying to create a variable with element xpath which has another variable in it. I created a keyword with argument and then set the value of the variable in the xpath as you can see in the example below.
*** Variables ***
${locator} //*[text() = β${helpVar}β]
${helpVar}
*** Keywords ***
Is it visible?
[Arguments] ${text}
${helpVar} Set Variable ${text}
Get Element States ${locator} contains visible
${text} this value can be form1 for example
I tried:
Log to console ${helpVar} - this logs form1 - so it changed
Log To Console ${locator} - but this variable is not affected as it still has no value in it: //*[text() = ββ]
I dont think thats possible even within python unless you use templates of some sort. Value of the variable is evaluted at when its defined or value is stored.
On python side something like this would be done with str.format() or with string.Template class. You could try to minic either one.
As you discovered the contents of ${helpVar} was evaluated at the time ${locator} was declared, so you canβt really do this as a global variable.
You could do it like this though if that helps:
*** Keywords ***
Is it visible?
[Arguments] ${text}
${helpVar} Set Variable ${text}
${locator} Set Variable //*[text() = β${helpVar}β]
Get Element States ${locator} contains visible