Cannot find elements when XPath expression is null

I have found out the cause of the problem in https://github.com/kazurayam/Cannot_find_elements_when_XPath_expression_is_null

Let me explain it.

I changed the test case TC1 . I inserted a few lines as follows:

import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature

TestObject to = findTestObject('Object Repository/Page_AngularJS Hub  Text Inputs/iframe_Example_exampleIFrame')

ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT)

println mapper.writeValueAsString(to)

When I run the TC1, the TestObject instance is printed as a JSON format string.

I ran TC1 twice. Once the error occurred. Then I did my “workaround”. Then one more run — One more time when no error occurred. I saved the JSON string into

I made a diff of a.json and b.json: diff.txt

64c64,67
<   "selectorCollection" : { },
---
>   "selectorCollection" : {
>     "BASIC" : "//iframe[@id = 'exampleIFrame' and @src = '/code/examples/forms/01_TextInputs/index.demo.php']",
>     "XPATH" : "//iframe[@id='exampleIFrame']"
>   },

Let me tell you what happened. The original Test Oject, as checked out of the repository, is printed like:

...
  "objectId" : "Object Repository/Page_AngularJS Hub  Text Inputs/iframe_Example_exampleIFrame",
  "imagePath" : null,
  "useRelativeImagePath" : false,
  "selectorMethod" : "XPATH",
  "selectorCollection" : { },
...

The Test Object in this status caused the error “Cannot find elements when XPath expression is null”.

After I did the workaround, the Test Object was changed to be:

"objectId" : "Object Repository/Page_AngularJS Hub  Text Inputs/iframe_Example_exampleIFrame",
  "imagePath" : null,
  "useRelativeImagePath" : false,
  "selectorMethod" : "XPATH",
  "selectorCollection" : {
    "BASIC" : "//iframe[@id = 'exampleIFrame' and @src = '/code/examples/forms/01_TextInputs/index.demo.php']",
    "XPATH" : "//iframe[@id='exampleIFrame']"
  },

I think this difference of selectorCollection element must be the cause of the problem.

I suppose that the selectorCollection element was introduced at v5.7.

It seems that the current Katalon Studio naively expects selectorCollection element to be NonNull. When it encounters empty selectorCollection, it throws IllegalArgumentException.

However, in the Katalon projects created before v5.7, possibly there are many Test Object instances without selectorCollection element. There seems to be some other cases in ver5.7 and later where a Test Object instance is left with empty selectorCollection element.

I want Katalon Studio to be more careful for and robust against those Test Object instance in older format.

2 Likes