# Passing String Variable in a selector is not working properly

**URL:** <https://discourse.openiap.io/t/passing-string-variable-in-a-selector-is-not-working-properly/3213>\
**Category:** OpenRPA\
**Created:** [December 10, 2025, 2:19pm UTC](https://discourse.openiap.io/t/passing-string-variable-in-a-selector-is-not-working-properly/3213 "2025-12-10T14:19:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ankita\_Rai](https://discourse.openiap.io/letter_avatar_proxy/v4/letter/a/e495f1/32.png) [@Ankita\_Rai](https://discourse.openiap.io/u/Ankita_Rai)\
**Post date:** [December 10, 2025, 2:19pm UTC](https://discourse.openiap.io/t/passing-string-variable-in-a-selector-is-not-working-properly/3213/1 "2025-12-10T14:19:31Z")

</div>

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**

 ![image](https://discourse.openiap.io/uploads/default/original/2X/0/050ecbe2639a1d6f4d755e2c560a8608afc79a88.png)

---

<div class="post-metadata">

**Author:** ![system](https://discourse.openiap.io/uploads/default/original/2X/a/a1ca7b164ac9a826839704d9ac82c7b5e6bcf557.png) [@system](https://discourse.openiap.io/u/system)\
**Post date:** [December 17, 2025, 2:19pm UTC](https://discourse.openiap.io/t/passing-string-variable-in-a-selector-is-not-working-properly/3213/2 "2025-12-17T14:19:35Z")

</div>

Closed on December 17, 2025, 2:19pm UTC

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