# Click an element if child element exists (while loop)

**URL:** <https://forum.katalon.com/t/click-an-element-if-child-element-exists-while-loop/15651>\
**Category:** Web Testing\
**Tags:** web-testing, katalon-studio\
**Created:** [December 18, 2018, 12:28pm UTC](https://forum.katalon.com/t/click-an-element-if-child-element-exists-while-loop/15651 "2018-12-18T12:28:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![erik.blomqvist](https://avatars.discourse-cdn.com/v4/letter/e/f6c823/32.png) [@erik.blomqvist](https://forum.katalon.com/u/erik.blomqvist)\
**Post date:** [December 18, 2018, 12:28pm UTC](https://forum.katalon.com/t/click-an-element-if-child-element-exists-while-loop/15651/1 "2018-12-18T12:28:20Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [December 18, 2018, 12:34pm UTC](https://forum.katalon.com/t/click-an-element-if-child-element-exists-while-loop/15651/2 "2018-12-18T12:34:15Z")

</div>

> [@erik.blomqvist](#):
>
> Action = WebUI.waitForElementVisible(findTestObject(hasNavObject), 1, FailureHandling.OPTIONAL)

If I’m following this correctly, try…

```auto
WebUI.waitForElementVisible(hasNavObject, ...

```

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [December 18, 2018, 12:40pm UTC](https://forum.katalon.com/t/click-an-element-if-child-element-exists-while-loop/15651/3 "2018-12-18T12:40:26Z")

</div>

and the same with the click, of course.

---

<div class="post-metadata">

**Author:** ![Marek\_Melocik](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/marek_melocik/32/371_2.png) [@Marek\_Melocik](https://forum.katalon.com/u/Marek_Melocik)\
**Post date:** [December 18, 2018, 12:41pm UTC](https://forum.katalon.com/t/click-an-element-if-child-element-exists-while-loop/15651/4 "2018-12-18T12:41:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![erik.blomqvist](https://avatars.discourse-cdn.com/v4/letter/e/f6c823/32.png) [@erik.blomqvist](https://forum.katalon.com/u/erik.blomqvist)\
**Post date:** [December 18, 2018, 12:42pm UTC](https://forum.katalon.com/t/click-an-element-if-child-element-exists-while-loop/15651/5 "2018-12-18T12:42:24Z")

</div>

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