Failure handling on Wait Until Page Contains Element

I’m new to the robots framework and I ask myself, what’s the ELSE case if an element is not found after the timeout of an action…

I do a lookup on a search field. The criteria may or may not yield a result. In the latter case, the result element is not found on the page and the keyword should return to the calling FOR loop and continue gracefully. TRY/EXCEPT does not seem to catch the not found case:

*** Keywords ***

Lookup Criteria
[Arguments] ${criteria}
Input Text search_field ${criteria}
TRY
Wait Until Page Contains Element css=div.resultElem
EXCEPT message
Log Not found: ${criteria}
RETURN
END

*** Test Cases ***
LOOKUP

FOR ${criteria} IN @{criterias}
Lookup Criteria ${criteria}
END

As mentioned, the test case LOOKUP is always terminated with a failure if not found, which is undesired behaviour.

Thanks for any hints.

Hi,

I would say the issue is in the EXCEPT syntax, where you’re expecting “message”.

If you specify something here, EXCEPT branch will be executed only in the case where the TRY failed with an error/string matching “message”.
I assume you rather have something like “Page did not contained element locator after x seconds”.

So first try to remove the condition to accept all failures:

TRY
     Wait Until Page Contains Element css=div.resultElem
EXCEPT
     Log Not found: ${criteria}
END

Btw the RETURN here might not be necessary as you return no variables. And take care of indentation too.

Regards
Charlie

2 Likes

Hi Charlie

Thanks for the hint! I removed the “message” param from EXCEPT and it worked fine. However, I had to stick with RETURN, otherwise the keyword wouldn’t return to the for loop.

Don’t worry about the the indentations, those were just scrapped by the forum’s block element…

Best,
Juerg