# Variable in xpath is not working

**URL:** <https://forum.katalon.com/t/variable-in-xpath-is-not-working/12912>\
**Category:** Miscellaneous\
**Created:** [August 29, 2018, 10:38am UTC](https://forum.katalon.com/t/variable-in-xpath-is-not-working/12912 "2018-08-29T10:38:35Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![sachin\_s\_petkar](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@sachin\_s\_petkar](https://forum.katalon.com/u/sachin_s_petkar)\
**Post date:** [August 29, 2018, 10:38am UTC](https://forum.katalon.com/t/variable-in-xpath-is-not-working/12912/1 "2018-08-29T10:38:35Z")

</div>

Hi All,  
I have gone through the existing discussion on forum related to how to use variables in xpath? and tried the different solutions but, still my script is failed.  
I have created a variable in variable tab (variable.jpeg) and used in objects xpath (xpath.jpeg)  
Same xpath I have used in script (Test.jpeg) with Click keyword. But, after execution it is showing me the below error in console.

**ERROR:** [FAILED] - Unable to click on object ‘Object Repository/Bids Page/Request ID’ (Root cause: org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression because of the following error:

SyntaxError: Failed to execute ‘evaluate’ on ‘Document’: The string ‘’ is not a valid XPath expression.

![](https://s3.amazonaws.com/katalon-forum/editor/f6/mefcc90xvaf6.jpg) ![](https://s3.amazonaws.com/katalon-forum/editor/ks/hxb319717xtm.jpg) ![](https://s3.amazonaws.com/katalon-forum/editor/g7/bn16uwzle1a1.jpg)

[variable.JPG](https://s3.amazonaws.com/katalon-forum/editor/f6/mefcc90xvaf6.jpg)

[xpath.JPG](https://s3.amazonaws.com/katalon-forum/editor/ks/hxb319717xtm.jpg)

[Test.JPG](https://s3.amazonaws.com/katalon-forum/editor/g7/bn16uwzle1a1.jpg)

---

<div class="post-metadata">

**Author:** ![sachin\_s\_petkar](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@sachin\_s\_petkar](https://forum.katalon.com/u/sachin_s_petkar)\
**Post date:** [September 6, 2018, 7:16am UTC](https://forum.katalon.com/t/variable-in-xpath-is-not-working/12912/2 "2018-09-06T07:16:56Z")

</div>

Can somebody help me for this issue?

---

<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:** [September 6, 2018, 7:26am UTC](https://forum.katalon.com/t/variable-in-xpath-is-not-working/12912/3 "2018-09-06T07:26:09Z")

</div>

Please copy and paste the code of your test case. I need to see the some lines around:

```auto
...WebUI.click(findTestObject('Object Repository/Bids Page/Request ID' .... ...

```

---

<div class="post-metadata">

**Author:** ![Noman\_Hafeez](https://avatars.discourse-cdn.com/v4/letter/n/b487fb/32.png) [@Noman\_Hafeez](https://forum.katalon.com/u/Noman_Hafeez)\
**Post date:** [November 14, 2018, 10:24am UTC](https://forum.katalon.com/t/variable-in-xpath-is-not-working/12912/4 "2018-11-14T10:24:03Z")

</div>

@4280-kazurayam I’m facing the same issue. I’m using a variable “del” in xpath.  
My xpath is as follows:  
//td[contains(.,’${del}’)]//preceding-sibling::td//label//input[@type=‘checkbox’]

---

<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:** [November 14, 2018, 11:53am UTC](https://forum.katalon.com/t/variable-in-xpath-is-not-working/12912/5 "2018-11-14T11:53:50Z")

</div>

Norman,

Please tell me the version of Katalon Studio. 5.6.x, 5.7.x or 5.8.x?

Please take screenshot of the Test Object definition. I need to see which Selection Method you chose.

Please show the test case code in script mode. I need to see how you call the findTestObject() method, which is related to the xpath in question.

---

<div class="post-metadata">

**Author:** ![Noman\_Hafeez](https://avatars.discourse-cdn.com/v4/letter/n/b487fb/32.png) [@Noman\_Hafeez](https://forum.katalon.com/u/Noman_Hafeez)\
**Post date:** [November 14, 2018, 12:46pm UTC](https://forum.katalon.com/t/variable-in-xpath-is-not-working/12912/6 "2018-11-14T12:46:34Z")

</div>

Version 5.8.6. And thanks for your prompt response.

 ![](https://dub1.discourse-cdn.com/katalon/uploads/default/original/1X/aa5d7ccc0bb96c353deaa9b15eac6666954625a1.png) ![](https://dub1.discourse-cdn.com/katalon/uploads/default/original/1X/56445ae094a4cb5b897a8ab6e73932bccd05373e.png)

[Test Object definition.png](https://forum.katalon.com/uploads/short-url/oj7sTi3tH1Z5E5r4mjFBR7Twblf.png)

[test case code.png](https://forum.katalon.com/uploads/short-url/cj9vLsPLseaiuzdjzOTcsaKnPeC.png)

---

<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:** [November 14, 2018, 1:02pm UTC](https://forum.katalon.com/t/variable-in-xpath-is-not-working/12912/7 "2018-11-14T13:02:49Z")

</div>

In the following doc

- [https://docs.katalon.com/katalon-studio/docs/parameterize-webmobile-test-object-properties.html](https://docs.katalon.com/katalon-studio/docs/parameterize-webmobile-test-object-properties.html)

you find

> Parameterizing Web/Mobile Test Object Properties is only available with Basic Attribute Selection Method.

Therefore you need to change the Selection Method first.

At the moment you have

Selection Metod: ●XPath ◎Attribute ◎CSS

Change this to

Selection Metod: ◎XPath ●Attribute ◎CSS

And, as a property of the Attribute selection method , you need to specify xpath manually:

Name | Condition | Value | Detect object by?

xpath | equals | …what you have now …| ☑

---

<div class="post-metadata">

**Author:** ![Noman\_Hafeez](https://avatars.discourse-cdn.com/v4/letter/n/b487fb/32.png) [@Noman\_Hafeez](https://forum.katalon.com/u/Noman_Hafeez)\
**Post date:** [November 14, 2018, 1:17pm UTC](https://forum.katalon.com/t/variable-in-xpath-is-not-working/12912/8 "2018-11-14T13:17:04Z")

</div>

Thank you! It’s working now but unable to get the correct data of column from excel file with this approach. Can you help with this?

---

<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:** [November 14, 2018, 1:19pm UTC](https://forum.katalon.com/t/variable-in-xpath-is-not-working/12912/9 "2018-11-14T13:19:07Z")

</div>

Please describe your problem with Excel data screenshots, test case code.

---

<div class="post-metadata">

**Author:** ![Noman\_Hafeez](https://avatars.discourse-cdn.com/v4/letter/n/b487fb/32.png) [@Noman\_Hafeez](https://forum.katalon.com/u/Noman_Hafeez)\
**Post date:** [November 14, 2018, 1:34pm UTC](https://forum.katalon.com/t/variable-in-xpath-is-not-working/12912/10 "2018-11-14T13:34:56Z")

</div>

I want to delete data(provided via excel file) from the grid(note that the data already exists).  
For this purpose I made a variable, and bind the column of excel file with this variable. And finally use this variable in xpath(of Test object). Finally called that test object in my test case. Please find attached screenshots for reference:

 ![](https://dub1.discourse-cdn.com/katalon/uploads/default/original/1X/3c3d6c18dbd5aa8388244cbf0eea557855454989.png) ![](https://dub1.discourse-cdn.com/katalon/uploads/default/original/1X/34d22acebb8b7ed0d6afcc4a2e76c6ed9e7b2cca.png) ![](https://dub1.discourse-cdn.com/katalon/uploads/default/original/1X/a7d43974456401d5462c1f519b10762c432bc2fe.png) ![](https://dub1.discourse-cdn.com/katalon/uploads/default/original/1X/cb7af95ad56ea45778dca881a9000d0364681f17.png) ![](https://dub1.discourse-cdn.com/katalon/uploads/default/original/1X/0dec8d4a3ed464a783eddddce40c3b5c6bc5c030.png)

[4.png](https://forum.katalon.com/uploads/short-url/8AUfb0FuoEoqe2xX6yb48ZQbzjr.png)

[1.png](https://forum.katalon.com/uploads/short-url/7xh6NurzUW1iifSZSlVckjokODg.png)

[2.png](https://forum.katalon.com/uploads/short-url/nWGqqJDM65CfyoayaYNzzIx4AUK.png)

[5.png](https://forum.katalon.com/uploads/short-url/t24oCJ6SZmw56E3EkRsj9ZzBIKr.png)

[3.png](https://forum.katalon.com/uploads/short-url/1Zb14kerPiDtQqoY7aF8jJF4OIM.png)

---

<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:** [November 14, 2018, 1:46pm UTC](https://forum.katalon.com/t/variable-in-xpath-is-not-working/12912/11 "2018-11-14T13:46:12Z")

</div>

Noman,

You mentioned

> unable to get the correct data of column from excel file

please describe what you found. What data do you expect from excel file, and what data do you get actually. How did you find it? Any error message, or println output?

---

<div class="post-metadata">

**Author:** ![Noman\_Hafeez](https://avatars.discourse-cdn.com/v4/letter/n/b487fb/32.png) [@Noman\_Hafeez](https://forum.katalon.com/u/Noman_Hafeez)\
**Post date:** [November 14, 2018, 4:26pm UTC](https://forum.katalon.com/t/variable-in-xpath-is-not-working/12912/12 "2018-11-14T16:26:16Z")

</div>

There is no error faced. However, the values on grid don’t get deleted according to the data of excel file.  
When I run the test case, the first row of grid gets deleted every time, irrespective of data of excel.

---

<div class="post-metadata">

**Author:** ![Noman\_Hafeez](https://avatars.discourse-cdn.com/v4/letter/n/b487fb/32.png) [@Noman\_Hafeez](https://forum.katalon.com/u/Noman_Hafeez)\
**Post date:** [November 14, 2018, 4:31pm UTC](https://forum.katalon.com/t/variable-in-xpath-is-not-working/12912/13 "2018-11-14T16:31:14Z")

</div>

Moreover, I get the expected result when I use hard-coded value in xpath instead of the above mentioned variable

---

<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:** [November 14, 2018, 10:22pm UTC](https://forum.katalon.com/t/variable-in-xpath-is-not-working/12912/14 "2018-11-14T22:22:31Z")

</div>

Let’s check the value of ‘del’ variable. Insert a line of debug-print and see what happens:

```auto
WebUI.click(findTestObject('DeleteUoI/Page_PAC ERP LigisticsUnit of Issue/Deletion', [('id'): del]))
WebUI.comment("the value of del variable was \"" + del + "\"")

```

Please describe what value of the del variable you expect, and what you see in the output from the WebUI.comment.

---

<div class="post-metadata">

**Author:** ![Noman\_Hafeez](https://avatars.discourse-cdn.com/v4/letter/n/b487fb/32.png) [@Noman\_Hafeez](https://forum.katalon.com/u/Noman_Hafeez)\
**Post date:** [November 15, 2018, 12:49pm UTC](https://forum.katalon.com/t/variable-in-xpath-is-not-working/12912/15 "2018-11-15T12:49:37Z")

</div>

Good day!  
Everything is working now. Thanks for your help. Talk to you in future
