# Unable to recognize variable text from XPATH SPAN

**URL:** <https://forum.katalon.com/t/unable-to-recognize-variable-text-from-xpath-span/56754>\
**Category:** Miscellaneous\
**Tags:** start-page\
**Created:** [July 20, 2021, 2:56pm UTC](https://forum.katalon.com/t/unable-to-recognize-variable-text-from-xpath-span/56754 "2021-07-20T14:56:50Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![btorrisi](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/btorrisi/32/16104_2.png) [@btorrisi](https://forum.katalon.com/u/btorrisi)\
**Post date:** [July 20, 2021, 2:56pm UTC](https://forum.katalon.com/t/unable-to-recognize-variable-text-from-xpath-span/56754/1 "2021-07-20T14:56:51Z")

</div>

Hi

Im having issues trying to use a variable inside a span for an xpath. The xpath from the page Im testing appears as follows:

 ![Screen Shot 2021-07-20 at 9.02.03 AM](https://europe1.discourse-cdn.com/katalon/original/3X/8/1/81a1bcd561b843021076ff607592f770ed370b3e.png)  
Im trying to identify the xpath using the bottom line showing the text “DNU ANF…”

Inside the object I know that this can work by entering part of the name into the xpath:

 ![Screen Shot 2021-07-20 at 9.06.42 AM](https://europe1.discourse-cdn.com/katalon/original/3X/2/a/2aeed6793bf30f1a9ec8e1329bc45b78a0e846ab.png)

However when I try and make the text in the span a variable, the variable does not seem to be read, Im pretty sure Ive got this set up incorrectly, but Im not sure where Im going wrong. This is how I’ve unsuccessfully attempted tried to make it a param:

 ![Screen Shot 2021-07-20 at 9.15.03 AM](https://europe1.discourse-cdn.com/katalon/original/3X/f/0/f01b1d6f358cc0e38dd6ed8646bced9a428d23e5.png)

The error I get with the above is:

> 54 INFO c.k.k.c.webui.common.WebUiCommonHelper - Unable to find the element located by ‘By.xpath: //\*[contains(text(), ‘${siteName}’)]’. Please recheck the objects properties to make sure the desired element is located.
> 
> > 2021-07-20 09:10:55.059 ERROR c.k.k.core.keyword.internal.KeywordMain - ❌ Unable to click on object ‘Object Repository/myWorldPortal/Sites/siteSearch’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to click on object ‘Object Repository/myWorldPortal/Sites/siteSearch’  
> > at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)  
> > at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)  
> > at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.click(ClickKeyword.groovy:75)  
> > at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:42)  
> > at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:73)  
> > at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:620)  
> > at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$2.call(Unknown Source)  
> > at createTransport\_privateFleet.run(createTransport\_privateFleet:46)  
> > at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)  
> > at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)  
> > at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:369)  
> > at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:360)  
> > at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:339)  
> > at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:331)  
> > at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:248)  
> > at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:191)  
> > at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:140)  
> > at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:89)  
> > at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:185)  
> > at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)  
> > at TempTestSuite1626786599223.run(TempTestSuite1626786599223.groovy:39)  
> > **\> \> Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/myWorldPortal/Sites/siteSearch’ located by ‘//\*[contains(text(), ‘${siteName}’)]’ not found**  
> > at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1368)  
> > at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:27)  
> > at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:26)  
> > at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$\_click\_closure1.doCall(ClickKeyword.groovy:66)  
> > at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$\_click\_closure1.call(ClickKeyword.groovy)  
> > at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)  
> > at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.click(ClickKeyword.groovy:75)  
> > at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:42)  
> > at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:73)  
> > at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:620)  
> > at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$2.call(Unknown Source)  
> > at Script1626493669424.run(Script1626493669424.groovy:46)  
> > … 13 more  
> > )  
> > 2021-07-20 09:10:55.066 ERROR c.k.katalon.core.main.TestCaseExecutor - ❌ Test Cases/End To End/createTransport\_privateFleet FAILED.  
> > Reason:  
> > com.kms.katalon.core.exception.StepFailedException: Unable to click on object ‘Object Repository/myWorldPortal/Sites/siteSearch’  
> > at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)  
> > at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)  
> > at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.click(ClickKeyword.groovy:75)  
> > at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:42)  
> > at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:73)  
> > at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:620)  
> > at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$2.call(Unknown Source)  
> > at createTransport\_privateFleet.run(createTransport\_privateFleet:46)  
> > at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)  
> > at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)  
> > at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:369)  
> > at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:360)  
> > at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:339)  
> > at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:331)  
> > at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:248)  
> > at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:191)  
> > at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:140)  
> > at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:89)  
> > at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:185)  
> > at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)  
> > at TempTestSuite1626786599223.run(TempTestSuite1626786599223.groovy:39)  
> > Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/myWorldPortal/Sites/siteSearch’ located by ‘//\*[contains(text(), ‘${siteName}’)]’ not found  
> > at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1368)  
> > at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:27)  
> > at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:26)  
> > at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$\_click\_closure1.doCall(ClickKeyword.groovy:66)  
> > at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$\_click\_closure1.call(ClickKeyword.groovy)  
> > at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)  
> > … 19 more

From the test case im simply trying to click on the object by using:

WebUI.click(findTestObject(‘myWorldPortal/Sites/siteSearch’))

Thanks in advance for any help

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [July 20, 2021, 3:50pm UTC](https://forum.katalon.com/t/unable-to-recognize-variable-text-from-xpath-span/56754/2 "2021-07-20T15:50:28Z")

</div>

Perhaps remove the single quotes you have around the variable so it becomes:

```auto
//*[contains(text(),${siteName})]

```

> [@XPATH with variables](http://forum.katalon.com/t/xpath-with-variables/10440/4):
>
> Why not have a look at this: Parameterize a Test Object [https://docs.katalon.com/display/KD/Parameterized+a+Test+Object](https://docs.katalon.com/display/KD/Parameterized+a+Test+Object) You will find an example of a Groovy-String as XPath with a ‘index’ variable. "//\*[@id="main"]/div/table/tbody/tr[2]/td[${index}]/input" And you can give value to the index variable with 2nd Map argument to findTestObject method call. WebUI.check(findTestObject('chk\_Title', [('index') : it])) See [https://api-docs.katalon.com/studio/v4.7.0/api/com/kms/katalon/core/testobj…](https://api-docs.katalon.com/studio/v4.7.0/api/com/kms/katalon/core/testobject/ObjectRepository.html#findTestObject(java.lang.String,%20Map%3CObject,%20Object%3E))

---

<div class="post-metadata">

**Author:** ![btorrisi](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/btorrisi/32/16104_2.png) [@btorrisi](https://forum.katalon.com/u/btorrisi)\
**Post date:** [July 20, 2021, 5:59pm UTC](https://forum.katalon.com/t/unable-to-recognize-variable-text-from-xpath-span/56754/3 "2021-07-20T17:59:46Z")

</div>

That also results in a a similar error - I tried that also and it still doesn’t recognize the variable, the error with the object as you suggested is:

> Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/myWorldPortal/Sites/siteSearch’ located by ‘//\*[contains(text(), ${siteName})]’ not found  
> at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1368)

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [July 20, 2021, 6:22pm UTC](https://forum.katalon.com/t/unable-to-recognize-variable-text-from-xpath-span/56754/4 "2021-07-20T18:22:26Z")

</div>

And if you use the actual text instead of the placeholder it works?

---

<div class="post-metadata">

**Author:** ![btorrisi](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/btorrisi/32/16104_2.png) [@btorrisi](https://forum.katalon.com/u/btorrisi)\
**Post date:** [July 20, 2021, 6:24pm UTC](https://forum.katalon.com/t/unable-to-recognize-variable-text-from-xpath-span/56754/5 "2021-07-20T18:24:17Z")

</div>

Yes that’s right - but what’s odd is that I use this variable elsewhere in my TC and its being read in fine.

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [July 20, 2021, 6:26pm UTC](https://forum.katalon.com/t/unable-to-recognize-variable-text-from-xpath-span/56754/6 "2021-07-20T18:26:41Z")

</div>

Sorry, maybe it was a typo on my part, but can you check if you have a parenthesis after the asterisk or a square bracket, like:

`//*[contains(text(),${siteName})]`

My last suggestion would be to use **double** quotes (not single) around the name, like below.

`//*[contains(text(), "${siteName}")]`

This is how I use it

![image](https://europe1.discourse-cdn.com/katalon/original/3X/6/6/66c86fe17b5cf43d49026b72f2106278c0d36d84.png)

---

<div class="post-metadata">

**Author:** ![btorrisi](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/btorrisi/32/16104_2.png) [@btorrisi](https://forum.katalon.com/u/btorrisi)\
**Post date:** [July 20, 2021, 6:55pm UTC](https://forum.katalon.com/t/unable-to-recognize-variable-text-from-xpath-span/56754/7 "2021-07-20T18:55:11Z")

</div>

Thanks @grylion54 appreciate the input but so far the error remains the same no matter what I try:

I tried the double quotes as well and it didn’t seem to have any different effect:

//_[contains(text(), ${siteName})]  
//_[contains(text(), “${siteName}”)]

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [July 20, 2021, 7:08pm UTC](https://forum.katalon.com/t/unable-to-recognize-variable-text-from-xpath-span/56754/8 "2021-07-20T19:08:08Z")

</div>

Just a note to put either a single **slanted** quote (to the left of the 1 on a qwerty keyboard) for single line or three **slanted** quotes for multi-line when you want to display text like you did above. Notice you are missing the asterisk in your xpath above but putting three **slanted** quotes above (and below) your text keeps the asterisk displayed.

```auto
//*[contains(text(), ${siteName})]
//*[contains(text(), "${siteName}")]

```

---

<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:** [July 20, 2021, 10:11pm UTC](https://forum.katalon.com/t/unable-to-recognize-variable-text-from-xpath-span/56754/9 "2021-07-20T22:11:02Z")

</div>

> [@btorrisi](#):
>
> …  
> at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$2.call(Unknown Source)  
> at createTransport\_privateFleet.run(createTransport\_privateFleet:46)  
> …

Please show us the code snippet of Line#46 of `createTransport_privateFleet`.

In that line, I guess your test case script calls `WebUI.click(findTestObject(....`. We need to see the exact detail of the line.

---

<div class="post-metadata">

**Author:** ![btorrisi](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/btorrisi/32/16104_2.png) [@btorrisi](https://forum.katalon.com/u/btorrisi)\
**Post date:** [July 21, 2021, 1:10pm UTC](https://forum.katalon.com/t/unable-to-recognize-variable-text-from-xpath-span/56754/10 "2021-07-21T13:10:00Z")

</div>

Hi @kazurayam here is a screen shot:

 ![Screen Shot 2021-07-21 at 9.09.07 AM](https://europe1.discourse-cdn.com/katalon/original/3X/4/6/466733aa27b6170250a80d7591551b45ad78a59e.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:** [July 21, 2021, 1:41pm UTC](https://forum.katalon.com/t/unable-to-recognize-variable-text-from-xpath-span/56754/11 "2021-07-21T13:41:51Z")

</div>

Your code is insufficient. You need to supply a key:value pair in order to interpolate the placeholder `${siteName}`.

See

> **[Parameterize Web Test Objects](https://docs.katalon.com/katalon-studio/docs/parameterize-web-objects.html#parameterize-web-test-objects-and-their-properties)**
>
> Parameterize Web Test Objects and their properties With parameterizing test objects, you can update test objects' locators dynamically by using either local or global variables. This feature comes in handy...

This document shows an example:

```auto
findTestObject('Page_Login/txtUserName', ['id' : '48415648'])

```

---

<div class="post-metadata">

**Author:** ![btorrisi](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/btorrisi/32/16104_2.png) [@btorrisi](https://forum.katalon.com/u/btorrisi)\
**Post date:** [July 21, 2021, 2:42pm UTC](https://forum.katalon.com/t/unable-to-recognize-variable-text-from-xpath-span/56754/12 "2021-07-21T14:42:35Z")

</div>

Thanks @kazurayam

Im struggling to know how to parameterize a test object when the value I want to inject comes from a CSV though.

my list comes from this data binding variable:

 ![Screen Shot 2021-07-21 at 10.40.40 AM](https://europe1.discourse-cdn.com/katalon/original/3X/7/f/7f47af3e5ab72013532bd4b954cd03148630980e.png)

What would I pass as the value for the test object?

 ![Screen Shot 2021-07-21 at 10.41.36 AM](https://europe1.discourse-cdn.com/katalon/original/3X/a/8/a80f2c039145ae220a31a137ef51641a82daa0ed.png)

Is almost like I want to pass a Test Variable inside the Object Variable?? Not sure if this can be done

---

<div class="post-metadata">

**Author:** ![btorrisi](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/btorrisi/32/16104_2.png) [@btorrisi](https://forum.katalon.com/u/btorrisi)\
**Post date:** [July 21, 2021, 5:52pm UTC](https://forum.katalon.com/t/unable-to-recognize-variable-text-from-xpath-span/56754/13 "2021-07-21T17:52:51Z")

</div>

Ok I think I worked it out. In case anyone else gets stuck here I was able to inject a test variable into an object variable by using the variable name in the value field of the object variable, where siteName was the variable in my csv:

 ![Screen Shot 2021-07-21 at 1.51.14 PM](https://europe1.discourse-cdn.com/katalon/original/3X/9/1/9152749a4d9319b7c2241952a19c135c8144ea94.png)

Then when I do the click in the my script, I mapped the test case variable to the object variable:

> WebUI.click(findTestObject(‘myWorldPortal/Sites/siteSearch’, [(‘siteSearch’) : siteName]))

---

<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:** [July 22, 2021, 5:36am UTC](https://forum.katalon.com/t/unable-to-recognize-variable-text-from-xpath-span/56754/14 "2021-07-22T05:36:54Z")

</div>

Closed on July 22, 2021, 5:36am UTC


