waitForElementVisible() produces false fails

I’ve noticed that this method is producing a Pass even when the element cannot be found. I do see that it stops the test case. However, shouldn’t this produce a fail?

I haven’t encountered this. Can you share your test code, the HTML involved, and the error logs? Also, you state:

I’ve noticed that this method is producing a Pass even when the element cannot be found.

There’s a difference between an element’s presence and its visibility. But again, without more information, this issue cannot be triaged. Thanks.

1 Like

My apologies, I was getting towards the end of the day when i wrote this. I will get code in ASAP. Although looking at katalon WEB examples i see they use markedPassed or Fail. I believe that

  1. They are using a try catch on the waits
  2. they may have markedPassed on the WebElementNotFound Catch

see example below for explanation

Once again, I apologize. I am new to Katalon. I will supply actual code, with comments ASAP

try {
WebElement element = WebUiBuiltInKeywords.findWebElement(to);
KeywordUtil.logInfo(“Clicking element”)
KeywordUtil.markPassed(“Element has been clicked”)
} catch (WebElementNotFoundException e) {
KeywordUtil.markFailed(“Element not found”)
} catch (Exception e) {
KeywordUtil.markFailed(“Fail to click on element”)

No need to apologize! It will just improve your turnaround time the more information we have to work with :grin: I will try to dig into this with what I think you’re getting at.

If we take a look at the source for the waitForElementVisible() keyword, there’s a catch block for the case when the element cannot be found in the DOM at all, which of course means the element is inherently not visible. In this case, a warning is logged and false is returned:

catch (WebElementNotFoundException e) {
    return false

This doesn’t necessarily mean the test has failed! For example, pretend we are testing some feature of an application where additional elements (maybe a dialog popup or something) may appear conditionally based on some other user actions. In this kind of scenario, we accept the possibility that the elements may not appear at all, but we need a wait condition in case they do.

If the script-writer explicitly wants the test to FAIL in the event that the element is not visible (either because it doesn’t exist, or otherwise), they should use the verifyElementVisible() keyword instead. This method acts as an assertion, whereas waitForElementVisible() acts as a wait condition:

if (element != null) {
   // some code to check for actual visibility...
else {
 WebUIKeywordMain.stepFailed(MessageFormat.format(StringConstants.KW_LOG_FAILED_ELEMENT_X_VISIBLE, to.getObjectId()), flowControl, null, true)
    return false

Notice that here, if the element is not present, then the step truly fails.

Hopefully this makes sense :expressionless: If this doesn’t answer your question, then I’d be happy to look at any other info you can share!

So the issue i feared showed up today.

The steps to produce are:

  1. Navigate to an element onClick() to display a Date Picker
    2 Verify the Element(Date Picker) is Visible

This Fails because of no wait functionality in VerifyElementVisible((). I cannot use VerifyElementPresent(), which does have a parameter to wait because the date picker is detectable in DOM. I guess what I am asking for is wait functionality in Verify visible. Also, I don’t want to use wait for Element Visible because if it is my last step, I am going to ge a false pass with a warning on the last step. I could do a wait, then a verify. It just doesn’t seem efficient to me.

1 Like

Luckily, the waitForElementVisible() method not only waits for the element to become visible within some timeout, but it also returns a boolean value based on the result.

So in your script, you can also ensure that the element was found and is visible (within the wait period) by asserting the result of the method call. I.e.:

assert waitForElementVisible(datePickerObject, 30);

This step will pass if the element is found and is visible within 30 seconds, and fail otherwise.

The verifyElementVisible() method basically handles this assertion for you, and checks for an element’s visibility right away.

Ahh, now that’s what i am looking for!!!
Thank you for your help

1 Like

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