# Create Xpath with variable data

**URL:** <https://forum.katalon.com/t/create-xpath-with-variable-data/43149>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [May 6, 2020, 12:33pm UTC](https://forum.katalon.com/t/create-xpath-with-variable-data/43149 "2020-05-06T12:33:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sstevens](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@sstevens](https://forum.katalon.com/u/sstevens)\
**Post date:** [May 6, 2020, 12:33pm UTC](https://forum.katalon.com/t/create-xpath-with-variable-data/43149/1 "2020-05-06T12:33:00Z")

</div>

Hi,  
I’m trying to create xpath using a variable that I create in my script.  
As a simple example, I am using the following to create a unique value in the variable newName each time the script runs. I’d like to be able to plug that variable into an xpath later in the script.

def time = now.getTime()

String name = ‘Form’

String newName = name + time

I’d like to be able to use this variable as part of an xpath so that I can locate it in a table or other places on page, as in:  
//input[@id=newName]

Can someone please advise on how to accomplish this or point me to the docs on it, which I can’t seem to find.  
Thanks

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [May 6, 2020, 12:45pm UTC](https://forum.katalon.com/t/create-xpath-with-variable-data/43149/2 "2020-05-06T12:45:31Z")

</div>

It’s usually something like `${your_variable_name}` in your xpath - but I’m not really an xpath guy so read through this Search Result:

[http://forum.katalon.com/search?q=variables%20in%20xpath](http://forum.katalon.com/search?q=variables%20in%20xpath)

---

<div class="post-metadata">

**Author:** ![ThanhTo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/thanhto/32/697_2.png) [@ThanhTo](https://forum.katalon.com/u/ThanhTo)\
**Post date:** [May 6, 2020, 5:19pm UTC](https://forum.katalon.com/t/create-xpath-with-variable-data/43149/3 "2020-05-06T17:19:30Z")

</div>

Here’s the doc:

> **[Web Test Object](https://docs.katalon.com/katalon-studio/docs/manage-web-test-object.html#parameterize-web-test-objects)**
>
> Create a Test Object Select File \> New \> Test Object from the main menu. The New Test Object dialog is displayed. Provide a name for the new test object, then click OK button. The new...

Basic idea is this:

```auto
// Initialize newName
TestObject to = findTestObject('your testobject id', ['newName': newName]);
println to.getSelectorCollection().toString(); // Should see your XPath which contains the actual value of newName, among other stuffs

```

In your Test Object, the selected locator should be: `//input[@id='${newName}']`

---

<div class="post-metadata">

**Author:** ![sstevens](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@sstevens](https://forum.katalon.com/u/sstevens)\
**Post date:** [May 6, 2020, 8:05pm UTC](https://forum.katalon.com/t/create-xpath-with-variable-data/43149/4 "2020-05-06T20:05:37Z")

</div>

Thanks. I was able to get it working based on this example.
