In Robot Framework, I want to reference the value of a variable, I had set earlier. But when I reference the value by:
xpath= //*[text()=\${uid}]
I do not get the value of the variable uid but instead, I get an error
InvalidSelectorException: Message: invalid selector:
Unable to locate an element with the xpath expression //*[text()=${uid}] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document':
The string '//*[text()=${uid}]' is not a valid XPath expression.
It just takes the uid
as the part of the XPath instead of referencing it. As you can see, I tried to escape the $
sign by adding a backslash (\
), but it doesn't do anything. It is not even shown in the expression shown in the error.
If anyone has any solution, kindly share them.
-
Please share your robot script as well.Bence Kaulics– Bence Kaulics2019年02月09日 16:05:21 +00:00Commented Feb 9, 2019 at 16:05
2 Answers 2
Have you tried putting the variable in double quotes?
//*[text()="${uid}"]
Here is one approach to call the XPath with dynamic value.
1.Create one python file name ConfigVariables.py
uid="test"
my_Xapth='xpath=//*[text()=\''+uid+'\']'
Save this file.
2.Import this file in .robot file under the setting keyword.
*** Settings ***
Variables ../Variables/ConfigVariables.py
Now try to call my_Xapth
variable in the test case, I hope this should work.
Explore related questions
See similar questions with these tags.