Unable to find an element using parameter in attributes (worked in the past)

Running Katalon Studio 8.6.8.
Using syntax that worked in the past, I cannot locate an element using a parameter in the object’s attributes.
Here is the object:

I am able to find the element with these attributes:

I am unable to find the element with a parameter defined as follows:

My code assigns a value to ‘id’ immediately before the ‘click’:
id = ‘minor-child2-dob’.

Here is the error message:
2023-11-08 17:19:13.992 DEBUG testcase.Experiments template - 10: id = “minor-child2-dob”
2023-11-08 17:19:13.995 DEBUG testcase.Experiments template - 11: click(findTestObject(“01 Customer Screens/004 1583 Assistant/1 - Step 0 and 1 Objects/Step 1 99 Parameter Test”))
2023-11-08 17:19:45.276 INFO c.k.k.c.webui.common.WebUiCommonHelper - Unable to find the element located by ‘By.xpath: //[@name = ‘${id}’ and @id = ‘${id}’]'. Please recheck the objects properties to make sure the desired element is located.
2023-11-08 17:19:45.499 ERROR c.k.k.core.keyword.internal.KeywordMain - :x: Unable to click on object ‘Object Repository/01 Customer Screens/004 1583 Assistant/1 - Step 0 and 1 Objects/Step 1 99 Parameter Test’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to click on object ‘Object Repository/01 Customer Screens/004 1583 Assistant/1 - Step 0 and 1 Objects/Step 1 99 Parameter Test’
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:74)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:40)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:620)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$4.call(Unknown Source)
at Experiments template.run(Experiments template:102)
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:448)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:144)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:135)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1699456722213.run(TempTestCase1699456722213.groovy:25)
Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/01 Customer Screens/004 1583 Assistant/1 - Step 0 and 1 Objects/Step 1 99 Parameter Test’ located by '//
[@name = ‘${id}’ and @id = ‘${id}’]’ not found
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1381)
at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:27)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$_click_closure1.doCall(ClickKeyword.groovy:65)
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:74)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:40)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:620)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$4.call(Unknown Source)
at Script1699164943408.run(Script1699164943408.groovy:102)
… 11 more
)
2023-11-08 17:19:45.502 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/Experiments template FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to click on object ‘Object Repository/01 Customer Screens/004 1583 Assistant/1 - Step 0 and 1 Objects/Step 1 99 Parameter Test’
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:74)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:40)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:620)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$4.call(Unknown Source)
at Experiments template.run(Experiments template:102)
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:448)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:144)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:135)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1699456722213.run(TempTestCase1699456722213.groovy:25)
Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/01 Customer Screens/004 1583 Assistant/1 - Step 0 and 1 Objects/Step 1 99 Parameter Test’ located by ‘//*[@name = ‘${id}’ and @id = ‘${id}’]’ not found
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1381)
at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:27)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$_click_closure1.doCall(ClickKeyword.groovy:65)
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)

I’ve searched the message boards and have tried many of the suggested solutions, but they have not worked. Thanks in advance.

1 Like

Did you form your parameterize statement like below? Note the second pair of square brackets within the paramerization as per KS.

WebUI.waitForElementVisible(findTestObject("01 Customer Screens/004 1583 Assistant/1 - Step 0 and 1 Objects/Step 1 99 Parameter Test", ['id': "minor-child2-dob", [('name'): "minor-child2-dob"]]), 10)
WebUI.click(findTestObject("01 Customer Screens/004 1583 Assistant/1 - Step 0 and 1 Objects/Step 1 99 Parameter Test", ['id': "minor-child2-dob", [('name'): "minor-child2-dob"]]))

Edit: if your id is unique, you do not need the name as well.

Edit2: I have done one parameterized variable within my code, but I have not done two, so I don’t know if one variable has to be first or not, like “name” then “id” or “id” then “name” or if it doesn’t matter.

Here is another idea that creates a Test Object in code at run time. Instead of the bulky parameterization statement, this to me is much “simpler” to look at.

Create a Keyword like @kazurayam or @Russ_Thomas have of the “makeTO” method and then pass the pathway (either CSS or XPath) to create a Test Object, like:

myAssistant = com.Tools.makeTO("//*[@name='minor-child2-dob' and @id='minor-child2-dob']")
WebUI.click(myAssistant)

Edit: Do NOT create two methods exactly alike to do CSS and XPath because you will get an error. You must have two different names; one to do CSS and another to do XPath, like “makeTO” which could do XPath and “createTO” which could do CSS (because the method starts with “C” ). :slight_smile:

@grylion54
Hi Mike. Thanks very much for your responses.
First - of course you are right that I needed to use only one unique ID, not both.
I was able to get it working per your first solution, passing in the value in the code.

However, what once worked in Katalon, where the object in the Repository has a value like ${id}, and “id” is a variable set in the code - does not seem to work any longer. I am continuing to check/try.

That solution allowed setting the ID to any dynamic value and not having to know the set of valid values in advance and passing them in explicitly. Sometimes the objects on the page have dynamic values - like username - and I can Get Text from Object A containing the username, set the “id” to that Text, and click on another object that has that “id” variable as an attribute value, where the “id” is evaluated in real time.

Some time ago, I had it working as described in

This screenshot is from the above doc. I have not gotten it to work using ${id} as in their example.

Thanks again.

@grylion54

I should have tried it before my last note - I see that your method allows for a variable to be passed in, as follows:
WebUI.click(findTestObject(“01 Customer Screens/004 1583 Assistant/1 - Step 0 and 1 Objects/Step 1 99 Parameter Test”, [‘id’: id]))

So if I grab “id” from a dynamic part of the screen, I can use it as an attribute value for a different object without explicitly listing in the call.

All the best.