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

1 Like

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

1 Like

@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

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