0

Trying to get an element attribute in robotframework, like so:

${list_id} = Get Element Attribute xpath://h3[contains(text(), ${name})] data-testid

All well and good, ${name} is a variable set higher up in the flow, but how do I wrap a variable so it is parsed as “XYZ” and not just XYZ? Without the quotes it’s an invalid xpath expression. Seen similar issues, but not many have included a variable.

Thanks, JB

1 Answer 1

2

Just wrap it in the quotes:

${list_id} = Get Element Attribute    xpath://h3[contains(text(), "${name}")]    data-testid

What will happen is RF will put the variable's value, and as you have quotes the xpath will end up as //h3[contains(text(), "XYZ")]

Sign up to request clarification or add additional context in comments.

2 Comments

That was what I tried initially, but this is what I see in the console: Element with locator 'xpath://h3[contains(text(), "$name")]' not found. I've set it as a suite variable, maybe it's not getting passed in? Will take another look.
Sorry, it should show as ${name}, was trying to pull it in without the curly braces, but that failed too.

Your Answer

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.