# How to Catch Assertion Error in Try & Except Block

**URL:** <https://forum.robotframework.org/t/how-to-catch-assertion-error-in-try-except-block/7367>\
**Category:** Browser\
**Created:** [4 June 2024 08:45 UTC](https://forum.robotframework.org/t/how-to-catch-assertion-error-in-try-except-block/7367 "2024-06-04T08:45:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![uditbhati1305](https://avatars.discourse-cdn.com/v4/letter/u/c5a1d2/32.png) [@uditbhati1305](https://forum.robotframework.org/u/uditbhati1305)\
**Post date:** [4 June 2024 08:45 UTC](https://forum.robotframework.org/t/how-to-catch-assertion-error-in-try-except-block/7367/1 "2024-06-04T08:45:54Z")

</div>

Hi All,

I am receiving an error: **AssertionError: Elements states ‘[‘attached’, ‘defocused’, ‘editable’, ‘enabled’, ‘visible’]’ (list) should be ‘[‘detached’]’ (list)**

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/3/334edb4482da4092baa260c4da7ea22450f1744d.png)

In this case, I’m waiting for an element state to become detached but sometimes it is not and the Assertion Error appears in the Log which causes the Test Execution to stop immediately.  
I’ve tried to catch this assertion error by using the below Try & Except:  
TRY  
Browser.Wait For Condition Element States ${Fetching\_Quote\_carrier} == detached timeout=01:00  
EXCEPT AssertionError: \* type=GLOB AS ${Error}  
Log ${Error}  
EXCEPT TimeoutError: \* type=GLOB AS ${Error}  
Log ${Error}  
END  
But this is not working.  
Can anyone suggest this?

---

<div class="post-metadata">

**Author:** ![Ivbot](https://avatars.discourse-cdn.com/v4/letter/i/ac8455/32.png) [@Ivbot](https://forum.robotframework.org/u/Ivbot)\
**Post date:** [4 June 2024 15:03 UTC](https://forum.robotframework.org/t/how-to-catch-assertion-error-in-try-except-block/7367/2 "2024-06-04T15:03:33Z")

</div>

I had a problem catching the exact timeout error and ended up using GLOB with \* on both sides of expected error message. Like this:

```
TRY
    Click locator
EXCEPT *Timeout 10000ms exceeded.* type=GLOB
    Log Timeout error caught, continuing the test
END

```

[Source](https://forum.robotframework.org/t/try-except-syntax/7335)

Maybe you could try this in your test:

```
TRY
    Browser.Wait For Condition Element States ${Fetching_Quote_carrier} == detached timeout=01:00
EXCEPT *AssertionError:* type=GLOB AS ${Error}
    Log ${Error}
EXCEPT *TimeoutError:* type=GLOB AS ${Error}
    Log ${Error}
END

```

---

<div class="post-metadata">

**Author:** ![uditbhati1305](https://avatars.discourse-cdn.com/v4/letter/u/c5a1d2/32.png) [@uditbhati1305](https://forum.robotframework.org/u/uditbhati1305)\
**Post date:** [5 June 2024 14:24 UTC](https://forum.robotframework.org/t/how-to-catch-assertion-error-in-try-except-block/7367/3 "2024-06-05T14:24:34Z")

</div>

Thanks, @Ivbot but I have already tried this approach and observed that in the case of AssertionError, the Test Case execution is getting terminated immediately.
