[WebUI] Verify Element Present


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

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.

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)

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.

@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,

@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.

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

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!!!

Hi
How is the verifyElementPresent used in katalon recorder?

@Fernando_Espinoza this topic is about katalon studio. for the recorder kindly use the dedicated topics and look for the dedicated documentation.

We are using 7.0.6, but still having this issue, below method doesn’t help, please advise.

WebUI.verifyElementPresent(findTestObject(‘someobject’, timeout, FailureHandling.OPTIONAL)

I’m using 7.0.7 and facing the same issue with WebUI.verifyElementNotPresent.
e.g. for an object I know is present in the dom, the step for WebUI.verifyElementPresent correctly passes. I expect that WebUI.verifyElementNotPresent for the same object fails but it’s not the case:
pass

It’s all marked green.

Hi @DianaF,

Please update to v7.0.10, we have fixed this issue.

Thank you so much! I updated to 7.0.10 and it works again as expected! :smile:

1 Like

I’m using 7.2.6 and facing the same issue with WebUI.verifyElementNotPresent.Kindly help me

Hello there,

I’m using version 7.2.1 and still facing the same issue. Currently I’m applying the work around mentioned in the chain. The output for the verifyElementPresent or verifyElementVisible is not true or false and hence unable to use them in If Else statement. Kindly advise.

Appreciate your help.

-Gowri

1 Like

Could you println the output? It should be true or false.

Is there any way to suppress the errors logged by Katalon when an element isn’t found? For example, if an element exists I want to do A, otherwise B.

if (WebUI.verifyElementPresent(element, timeOut, FailureHandling.OPTIONAL) {
A
} else {
B
}

If “element” is not found, I’ll get a garbage readout like:

Unable to find the element located by ‘By.xpath: //span[@class=“element-xpath”]’. Please recheck the objects properties to make sure the desired element is located.

Is there a better way to check for elements or mute these “errors”?

I’m unable to print output in the console

@kyilmaz

PLS Have a look at

1 Like