# WebUI.waitForElement\*() not throwing exception

**URL:** <https://forum.katalon.com/t/webui-waitforelement-not-throwing-exception/26426>\
**Category:** Bug Report\
**Tags:** bugs-report, katalon-studio\
**Created:** [May 28, 2019, 9:43am UTC](https://forum.katalon.com/t/webui-waitforelement-not-throwing-exception/26426 "2019-05-28T09:43:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![imeelmax](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/imeelmax/32/5371_2.png) [@imeelmax](https://forum.katalon.com/u/imeelmax)\
**Post date:** [May 28, 2019, 9:43am UTC](https://forum.katalon.com/t/webui-waitforelement-not-throwing-exception/26426/1 "2019-05-28T09:43:40Z")

</div>

(Windows 10 / CentOS Linux release 7.6.1810) Katalon Studio Version: 6.1.5 build 3  
Default Failure Handling for Test Step: STOP\_ON\_FAILURE

I’m testing for an element that becomes present or clickable for several seconds.  
waitForElementPresent() and waitForElementClickable() notice the element and:

- return a true or false conform the element state
- omit throwing an exception if not present

Reproducable: Always

Sample code:

```
def present1 = false, present2 = false
try {
  present1 = WebUI.waitForElementPresent(findTestObject('Object Repository/TestPage/msgBox'), 1)
  println ( "This line should not be printed if element is Not present: $present1" )
  present2 = WebUI.waitForElementPresent(findTestObject('Object Repository/TestPage/msgBox'), 1,
      FailureHandling.STOP_ON_FAILURE )
  println ( "This line should not be printed if element is Not present: $present2" )
}
catch ( Exception e ) {
  // This is never being called
  println ( "Exception: $e" )
}
finally {
  println ( "Final: element is present1: $present1 present2: $present2" )
}

```

Sample Log Viewer:

```
WARNING Web element with id: ... not found

```

Sample Console result:

```
INFO Unable to find the element located by 'By.xpath
...
This line should not be printed if element is Not present1: false
INFO Unable to find the element located by 'By.xpath
...
This line should not be printed if element is Not present2: false
Final: element is present1: false present2: false

```

---

<div class="post-metadata">

**Author:** ![imeelmax](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/imeelmax/32/5371_2.png) [@imeelmax](https://forum.katalon.com/u/imeelmax)\
**Post date:** [May 29, 2019, 9:06am UTC](https://forum.katalon.com/t/webui-waitforelement-not-throwing-exception/26426/3 "2019-05-29T09:06:34Z")

</div>

Workaround:

```auto
  import com.kms.katalon.core.exception.StepErrorException as StepErrorException
  import com.kms.katalon.core.exception.StepFailedException as StepFailedException

  present1 = WebUI.waitForElementPresent(findTestObject('Object Repository/TestPage/msgBox'), 1)
  if ( present1 ) throw new StepFailedException ( "Cant find msgBox" )

```

or if you like

```auto
  if ( WebUI.waitForElementPresent(findTestObject('Object Repository/TestPage/msgBox'), 1) ) {
    throw new StepFailedException ( "Cant find msgBox" )
  }
```

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/katalon/original/3X/d/5/d55596ab02785a255798e87ede769734747b30c4.svg) [@system](https://forum.katalon.com/u/system)\
**Post date:** [May 28, 2020, 9:06am UTC](https://forum.katalon.com/t/webui-waitforelement-not-throwing-exception/26426/4 "2020-05-28T09:06:35Z")

</div>

Closed on May 28, 2020, 9:06am UTC

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
