How to handle exception ElementNotFound: in robot framework

I want to handle exception ElementNotFound: in my code. But rather test should pass but it FAIL.

Click on HideShow button
Click ${HideShowBtn}
Sleep 1
TRY
${TitleComboBoxStatus} = Get Attribute ${TitledOption} IsEnabled
Log To Console Status of Titled ComboBoxes : ${TitleComboBoxStatus}
${UntitleComboBoxStatus} = Get Attribute ${UntitledOption} IsEnabled
Log To Console Status of Untitled ComboBoxes : ${UntitleComboBoxStatus}
IF ${TitleComboBoxStatus} and ${UntitleComboBoxStatus}
Fail Combo Boxes are not Hidden Successfully
ELSE
Log To Console Status of Comboboxes : Enabled
END
EXCEPT ElementNotFound:
Log To Console Combo Boxes are Hidden Successfully
END

I have a scenario when i want to click on “HideShow” button and there are elements “TitledOption” and “UntitledOption” are hidden. So i want to check if e.g. Element are not hidden then test should FAIL. and when these elements are hidden then test should Pass and message should display in Log .

Now when my code is run then test case is FAIL with error ElementNotFound: Element not found with locator 'id: …

How can i resolve the issue.? Please guide.
Thanks

Have a look at Run Keyword And Return Status, but actually look at all the Run Keyword And * keywords and see which one best suits your needs.

Dave.

1 Like