1

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.

1
  • Please share your robot script as well. Commented Feb 9, 2019 at 16:05

2 Answers 2

1

Have you tried putting the variable in double quotes?

 

//*[text()="${uid}"]
0

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.

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.