Identify an element on webpage dynamically

Hi gurus,

I am trying to dynamically identify (or click) an element on a web-application, using the Spy, the xpath does not generate anything meaningful, but I see that there is an attribute (text) that uniquely identifies the element.

However, I am having trouble getting Katalon to identify the element during runtime, but maybe my code is not correct?
{PatientName} = variable defined at testcase level
WebUI.click(findTestObject(“page_Patient_Search/*[(text() =’{PatientName}’”))

When I run my test, I keep failing at the line with the error:

11-20-2019 03:15:04 PM Test Cases/Create_Unit_Dose

Elapsed time: 31.383s

Test Cases/Create_Unit_Dose FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementPresent() is applicable for argument types: (null, com.kms.katalon.core.model.FailureHandling) values: [null, STOP_ON_FAILURE]

Please help!

This line of code:

WebUI.click(findTestObject(“page_Patient_Search/*[(text() =’{PatientName}’”))

did not produce this error:

groovy.lang.MissingMethodException: No signature of method: 
static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementPresent() 
is applicable for argument types: (null, com.kms.katalon.core.model.FailureHandling) values: [null, STOP_ON_FAILURE]

In future, if you expect help from “gurus” please be sincere about the code you are using and the errors you receive.

Okay, first thing wrong based on what I see:

WebUI.click() needs a TestObject. findTestObject() needs a String which is a path to a TestObject (usually stored in the Object Repository) <- you are passing in a String containing an XPath. So, when findTestObject() fails to find a TestObject, it passes null (nothing) to WebUI.click(). Bang.

Look at the example here:

Now, looking at your error, I suspect once again, you are not giving findTestObject() what it needs - the error is saying you passed null to verifyElementPresent() as the first argument and it too requires a TestObject (same as before).

You really should spend some time working through the examples so that you can become proficient at working with Katalon Groovy code.

Start here:

Hey Russ_Thomas, not sure why you mentioned that I need to be sincere about the code I’m using, I’m a newbie using Katalon, if there’s something that I am not providing or I’m doing incorrectly, please do let me know. My apology in advance if I am doing something wrong here. But I do wanna thank you for taking the time to help me out with my problem.

So as I had stated above, I am trying to get Katalon to identify a textlink dynamically because the textlink will be based on the search at the time.

Using the Spy, I am unable to get anything unique
spy4

so I opted for something dynamic.

I looked through the docs you included, and I have tried the following, but not sure what the issue is:

WebUI.click(findTestObject(“page_Patient_Search/link_PatientName”))

In the Test Case, in the Variables tab, I have a string parameter called PatientName

Katalon has problem clicking the object

Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to click on object ‘Object Repository/page_Patient_Search/link_PatientName’

Would be much appreciate it if someone can point out what I am doing wrong here? Thanks!

I requested, using the word please that you report your problem clearly. You claimed a certain line of code produced a certain error. I don’t believe that’s true. WebUI.click() does not produce errors talking about verifyElementPresent().

You do NOT need to apologize, Michael. And yes, you are doing something wrong - we’ll come to that in a minute. What we need is a clearly stated issue and a specific error caused by that issue. That’s all. I’m sorry if you take umbrage with my remarks, but I am trying to help you. If you report issues properly, things will go smoother.

At least now we have an issue (click) reporting an error about click.

Now go back to your error and find the “Caused by” part. That will help a lot.

For future reference, follow this guide to ask questions and make great reports:

Hi Russ, I appreciate the clarification, sorry that I submitted an incomplete issue, which was hindering others from helping my case.

So here is the full log:

11-21-2019 11:14:12 AM Test Cases/Create_Unit_Dose

Elapsed time: 1m - 0.503s

Test Cases/Create_Unit_Dose FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to click on object ‘Object Repository/page_Patient_Search/link_PatientName’
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:86)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:67)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:616)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$2.call(Unknown Source)
at Create_Unit_Dose.run(Create_Unit_Dose:54)
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:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1574363647996.run(TempTestCase1574363647996.groovy:21)
Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/page_Patient_Search/link_PatientName’ located by ‘By.xpath: //*[(text() = ‘${PatientName}’ or . = ‘${PatientName}’)]’ not found
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1097)
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:77)
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)
… 17 more

That’s the real problem. Check that XPath is working correctly.

By the looks of it, your xpath is actually fine. The problem is that your variable handles within the xpath are not getting populated. Assuming that the below code is how you are calling the test object:

You should instead be providing the variables that you want to replace, like so:

WebUI.click(findTestObject(“page_Patient_Search/link_PatientName”, ['PatientName' : PatientName]))

1 Like

Hi guys,

I am providing all the info that I have in hope to help you guys understand my problem and hopefully a solution can be suggested.

dynamic tag.html (50.3 KB)

To answer Russ’ question about checking the XPath, Katalon is able to identify the link

//*[(text() = 'CHEN,PHARMACY ’ or . = 'CHEN,PHARMACY ')]

Now looking at the error log, it says

Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/page_Patient_Search/link_PatientName’ located by ‘By.xpath: //*[(text() = ‘${PatientName}’ or . = ‘${PatientName}’)]’ not found

Is because ${PatientName} (defined in the object, specifically, the text link tag), is not pulling the variable value that is set at the Test Case level? If so, how do I connect the two? Thanks!

See my answer above, you may have missed it.

Hi Brandon, much thanks to the suggestion above, it worked!

2 Likes