[WebUI] Verify Element Present


#1

This is a companion discussion topic for the original entry at https://docs.katalon.com/katalon-studio/docs/webui-verify-element-present.html

#2

The signature of this method says it returns a Boolean, either if the element is present or not.

According with my tests, a Boolean true is returned if the element is present which is the positive case, but if the element is not present, it always throws an exception (StepFailedException), so never returns false. This is a contradiction with the method documentation.

On the other hand I think the natural behaviour of the method would be as it documents (return true in case of present and return false in case it’s not present), and let the tester decide if to throw an exception or not in case of a false return.

Sumarizing: I think there is a bug in this method because

  1. It does not follow what its documentation promises
  2. The normal (or expected) behaviour for verify… methods should be to return true or false (and let the tester decide whether to raise an exception or not once the method has returned)
  3. Raise an exception only in case of an exceptional event, for example when the passed test object does not exists in the Object Repository

I don’t know if all other verify… methods have the same behaviour like this.

I would like to listen the community what others think about what should be the normal / expected behaviour of this metiod and other similar ones.


#3

Indeed, I’ve seen that method KeywordUtil.markFailed() always raises an exception (StepFailedException), so I think when you write a custom keyword, there is no way to return from a method, markind it as failed: you always raises an exception.

¿ Is this behaviour the most appropriated ?

(perhaps this is the root cause why verifyElementPresent raises an exception in the negative case)


#4

Hello Team katalon,

This method is not working as expected. This is returning “true” even when the webelement is not present.
Please let me know, if there is any alternate solution to this.


#5

@Madhu.basavaraja @Enrique_Castilla
Hello Team Katalon,

I have the same problem: this method isn’t working as expected. It’s returning “true” even when the webelement is not present.

Please let’s me know, if there is any alternate solution to this case.

Best regards,


#6

@Katalon Developers : Would be able to provide update on this. When can we expect fix on this ?

All the verify methods have the same behavior for negative cases, it throws exception instead of returning boolean false, when the verify statement fails.


#7

Hi @Enrique_Castilla, @Madhav_Choudhary, @Madhu.basavaraja

Please try with this workaround solution:

WebUI.verifyElementPresent(findTestObject(''), timeout, FailureHandling.OPTIONAL)

We will update this fix in v6.4.0.

Thanks


#8

Hi Everyone, the method returns True and False on the presence and absence of an element respectively. However, it also throws the StepFailedException if the element is absent (which should be mentioned in the documentation). In order to overcome this problem, we have to set the Failure Handling to optional by passing third argument. Therefore, the method would be
WebUI.verifyElementPresent(findTestObject(‘someobject’, timeout, FailureHandling.OPTIONAL)

This would definitely work!!!