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. Feb 9, 2019 at 16:05

2 Answers 2


Have you tried putting the variable in double quotes?



Here is one approach to call the XPath with dynamic value.

1.Create one python file name ConfigVariables.py


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.