WebUI.waitForElement*() not throwing exception

(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
1 Like

Workaround:

  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

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

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