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.

Bence Kaulics
1,00712 silver badges22 bronze badges
asked Feb 5, 2019 at 8:57
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}"]
answered Feb 9, 2019 at 7:55
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.

Bence Kaulics
1,00712 silver badges22 bronze badges
answered Sep 25, 2019 at 10:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.