# Create a dynamic Xpath with TestObject / Mobile

**URL:** <https://forum.katalon.com/t/create-a-dynamic-xpath-with-testobject-mobile/51056>\
**Category:** Mobile Testing\
**Tags:** mobile-testing, katalon-studio\
**Created:** [January 14, 2021, 2:52pm UTC](https://forum.katalon.com/t/create-a-dynamic-xpath-with-testobject-mobile/51056 "2021-01-14T14:52:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![olivier](https://avatars.discourse-cdn.com/v4/letter/o/d2c977/32.png) [@olivier](https://forum.katalon.com/u/olivier)\
**Post date:** [January 14, 2021, 2:52pm UTC](https://forum.katalon.com/t/create-a-dynamic-xpath-with-testobject-mobile/51056/1 "2021-01-14T14:52:14Z")

</div>

Hello,

I’m using KS 7.8.2 / mobile application

I am trying to create a dynamic xpath using the TestObject class.  
This is my code :

```
String myXpath = "(//*[(@resource-id = \'fr.myObject:id/retour_lib\' and @text = \'2004210154605 - 337 - FILLE\' or . = \'2004210154605 - 337 - FILLE\')]//following::android.widget.TextView[@resource-id=\'fr.myObject:id/case_more\'])[1]"

TestObject myNewObject = new TestObject ('CLIC_PLUS')
myNewObject.setSelectorValue (SelectorMethod.XPATH, myXpath)
myNewObject.setSelectorMethod (SelectorMethod.XPATH)
Mobile.tap (myNewObject, 1, FailureHandling.OPTIONAL)

```

When i run i have no error (or no warning) but it doesn’t click on the right object …  
If I put exactly the same Xpath string directly in the object repository with the Xpath method then it finds it correctly and clics on the right object.

What am I doing wrong?

Thank you
