Passing String Variable in a selector is not working properly

I’m trying to click candidate names dynamically on a webpage using OpenRPA. The page contains multiple candidates, and I’m iterating through them using a For Each loop, where each item in the loop is a string variable (Candidate) coming from a List(Of String).

When I hard-code the candidate name inside the XPath selector (example:
"//span[contains(text(),'Tushar Khaple')]"), the Click Element activity works correctly.

But when I replace the hard-coded value with the loop variable (e.g., Candidate), sometimes the selector works but most of the time it fails to locate the element.

Here is the XPath I’m using:
“//span[contains(text(),‘{{Candidate}}’)]”
So my question is:

Why does the selector work with static text but fail when the candidate name is passed as a string variable from the For Each loop?
Attaching a reference image of webpage where i want to click on each candidate name one by one

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.