Click an element if child element exists (while loop)

Hi!

I’m pretty new to Katalon Studio, but after some googling and going through the forums, I think have a pretty decent idea of how to achieve what I want to do, but I’m not sure how to deal with the error message I’m getting (posted after the code).

What I’m trying to achieve
I have a website with a grid of items that appear based on a search result. Some of these grid items have a navigation in them, some don’t. I want to click the first item that has this inner navigation.

My code
Integer GridNumber = 1
Boolean Action = false

while (true) {

  String xpathValue = 'div[@id="app"]/div/div[@class="main-content"]/div[3]/div[2]/div[@class="container"]/div/div[@class="grid-items"]/div[' + GridNumber + ']/div/div[@class="product-card__navigation"]'

  TestObject hasNavObject = new TestObject()

  hasNavObject.addProperty(
    'xpath',
    ConditionType.EQUALS, 
    xpathValue
    )

  WebUI.delay(1)
  Action = WebUI.waitForElementVisible(findTestObject(hasNavObject), 1, FailureHandling.OPTIONAL)

  if (Action == true) {
    WebUI.click(findTestObject(hasNavObject))
  } else {
    continue
  }

  GridNumber++
}

(ConditionType is imported before this)

The error message
while (true) FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.testobject.ObjectRepository.findTestObject() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject) values: [TestObject - ‘’]
Possible solutions: findTestObject(java.lang.String), findTestObject(java.lang.String, java.util.Map)
at Change fabric.run(Change fabric:44)
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:321)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:312)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:291)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:283)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:222)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1545135499873.run(TempTestCase1545135499873.groovy:22)

If I’m following this correctly, try…

WebUI.waitForElementVisible(hasNavObject, ...
2 Likes

and the same with the click, of course.

As Russ mentioned - this is a method definition

boolean waitForElementVisible(TestObject to, int timeout)

You need

TestObject findTestObject(String objectPathInRepository)

to get the test object from the repository.

As soon as you define your TestObject within a test or keyowrd, you don’t need findTestObject(…) anymore. Just pass the object itself to the waitFor (and any other) method

1 Like

Wasn’t more complicated than that. Thanks a lot!

1 Like