TRY EXCEPT syntax

Hi All,

Can I give exact error that I am expecting (e.g. Timeout Error) and catch it in EXCEPT block instead of Fatal Error?
I tried it but I cannot figure out the syntax.

e.g.
I am expecting following error if there is no button displayed
TimeoutError: locator.myLocator: Timout 1000ms exceded.

Where do I write and what exactly? The whole error message?

TRY
    Click    ${myLocator}
EXCEPT
    Log    Button not displayed (as expected), continuing the test
END

Yes, it is in the first paragraphs of the documentation, here.

1 Like

This works if I do not put any specific error.

But, if I try to catch some specific error my test fail.

This is the log:

I’ve tried with this, but it does not work:
TRY
Click ${Alert.Success}
EXCEPT TimeoutError: locator.click: Timeout 10000ms exceeded.
Log The element is not displayed
END

You are adding the error report part of Robot Framework. Use only the library error:

EXCEPT    Timeout 10000ms exceeded.

And try to use GLOB or RegEx.

Also you can try to use Wait Until Element is Visible before clicking.

1 Like

I have already tried GLOB, but looks like the only thing that works is putting the * both at the beginning and at the end, like this:

EXCEPT    *Timeout 10000ms exceeded.*    type=GLOB

This solves my problem for now. Thanks!

Blockquote
Also you can try to use Wait Until Element is Visible before clicking.

I am using Browser library, so I use Wait For Elements State in this specific case.

1 Like