# Failure handling on Wait Until Page Contains Element

**URL:** <https://forum.robotframework.org/t/failure-handling-on-wait-until-page-contains-element/8101>\
**Category:** SeleniumLibrary\
**Created:** [22 November 2024 15:10 UTC](https://forum.robotframework.org/t/failure-handling-on-wait-until-page-contains-element/8101 "2024-11-22T15:10:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JuergMeier](https://avatars.discourse-cdn.com/v4/letter/j/eada6e/32.png) [@JuergMeier](https://forum.robotframework.org/u/JuergMeier)\
**Post date:** [22 November 2024 15:10 UTC](https://forum.robotframework.org/t/failure-handling-on-wait-until-page-contains-element/8101/1 "2024-11-22T15:10:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [22 November 2024 17:32 UTC](https://forum.robotframework.org/t/failure-handling-on-wait-until-page-contains-element/8101/2 "2024-11-22T17:32:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JuergMeier](https://avatars.discourse-cdn.com/v4/letter/j/eada6e/32.png) [@JuergMeier](https://forum.robotframework.org/u/JuergMeier)\
**Post date:** [26 November 2024 15:40 UTC](https://forum.robotframework.org/t/failure-handling-on-wait-until-page-contains-element/8101/3 "2024-11-26T15:40:12Z")

</div>

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
