Stuggling with passing variable to object's xpath

The message “com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id:... not found” implies 2 possible cases:

  1. The locator is right but your code tries to get access to the WebElement in a web page too soon when the WebElement is not yet visible in the browser. So that you test code fails to find the WebElement in the page.
  2. The locator (xpath or css selector) is wrong; it points no WebElement present. It will fail anyway regardless timing.

@grylion54 thought of the case 1. So he advised to you to let your test code wait for the WebElement becomes present and visible. Why not you give his suggestion a chance? Please try it.

Concerning the probability of the case 2, I do not see anything. If we are to check the locator’s validity, we need more information to be shared, such as:

  1. how your target HTML source looks like. If the target URL is publicly accessible, then share it to us. If not, make a zip of HTML and publish it here.
  2. how your test case code calls findTestObject(testobject)
  3. how your test object is defined
  4. when executed what locator you expect to be generated by the findTestObject()
  5. when executed what locator you actually got

But checking the xpath validity remotely is often difficult in the forum discussion format.

I would rather suggest you to create a simpler test case which just calls:

WebUI.openBrowser(yourURL)
WebUI.verifyElementPresent(findTestObject(testObjectName, params), 10)

This code would make you concentrated to a single issue: if the xpath generated by findTestObject is right or wrong.

thanks @kazurayam will try your suggestions and @grylion54 as well. And share the relevant info you asked for.

Hi @grylion54 and @kazurayam how to handle the Global variable for this below xpath, Please reply Soon

Xpath:
(//span[text()='Case : '])[2]

Global variable profile:
‘${GlobalVariable.Case}’

Sorry, but what do you mean by “handle”? If you are trying to make a global String then you can try:
GlobalVariable.Case = '(//span[text()="Case : "])[2]'

If you are trying to get the phrase, 'Case :', into the xpath, and GlobalVariable.Case contains the phrase, then you can try creating a Test Object with the xpath as:
"(//span[text()=${msg}])[2]"

and then using the Test Object like:

WebUI.setText(findTestObject(..., ['msg' : GlobalVariable.Case]), "CS1456")

It looks like you have all the information and assignment. I personally don’t like arrays (they seem to break more often), but if that is what you have, then that is what you go with.