# Dynamic Xpath is not working by passing variable to the xpath

**URL:** <https://forum.katalon.com/t/dynamic-xpath-is-not-working-by-passing-variable-to-the-xpath/54623>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [May 10, 2021, 2:31pm UTC](https://forum.katalon.com/t/dynamic-xpath-is-not-working-by-passing-variable-to-the-xpath/54623 "2021-05-10T14:31:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bikram.kumar.nayak](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/bikram.kumar.nayak/32/16104_2.png) [@bikram.kumar.nayak](https://forum.katalon.com/u/bikram.kumar.nayak)\
**Post date:** [May 10, 2021, 2:31pm UTC](https://forum.katalon.com/t/dynamic-xpath-is-not-working-by-passing-variable-to-the-xpath/54623/1 "2021-05-10T14:31:18Z")

</div>

Hi, I am passing variable as SearchText = “Studies”

My dynamic xpath is Xpath=//one-app-launcher-menu-item/a//p/b[text()=’${SearchText}’]  
which is not working.

If i give hardcoded xpath as xpath as //one-app-launcher-menu-item/a//p/b[text()=‘Studies’] which is working.

while passing the variable in Searchtext , the xpath is not able to searched and give error as "Unable to find the element located by ‘By.xpath: //one-app-launcher-menu-item/a//p/b[text()=’${SearchText}’]’. Please recheck the objects properties to make sure the desired element is located. "  
Please let me know if i am missing anything and how to dynamically pass the variable.  
Thanks!!

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [May 10, 2021, 4:30pm UTC](https://forum.katalon.com/t/dynamic-xpath-is-not-working-by-passing-variable-to-the-xpath/54623/2 "2021-05-10T16:30:11Z")

</div>

You need to pass a list of key:value pairs as the 2nd parameter to `findTestObject` method.  
For example:

```auto
WebUI.setText(findTestObject(testObjectId, ['SearchText': 'Studies']), "Happy birthday!")

```

Please share your test case script if you have further question.

---

<div class="post-metadata">

**Author:** ![bikram.kumar.nayak](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/bikram.kumar.nayak/32/16104_2.png) [@bikram.kumar.nayak](https://forum.katalon.com/u/bikram.kumar.nayak)\
**Post date:** [May 10, 2021, 6:14pm UTC](https://forum.katalon.com/t/dynamic-xpath-is-not-working-by-passing-variable-to-the-xpath/54623/3 "2021-05-10T18:14:31Z")

</div>

Thanks!! it worked

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [May 11, 2021, 9:56am UTC](https://forum.katalon.com/t/dynamic-xpath-is-not-working-by-passing-variable-to-the-xpath/54623/4 "2021-05-11T09:56:05Z")

</div>

Closed on May 11, 2021, 9:56am UTC


