Unable to recognize variable text from XPATH SPAN

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:


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:

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:

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 - :x: 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 - :x: 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

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

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

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)

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

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

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

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}”)]

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.

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

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.

Hi @kazurayam here is a screen shot:

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

See

This document shows an example:

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

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:

What would I pass as the value for the test object?
Screen Shot 2021-07-21 at 10.41.36 AM

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

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

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]))