Better exception messages on UiElement not found

Hi,

When using the Object Respository and an element can not be found (e.g. when a pop-up prevents the robot from going to the next screen), we get the following generic exception message.

Could not find the user-interface (UI) element for this action.
Possible solutions:
• Ensure application is opened and the UI element is visible on the screen at execution time
• Edit the Target of the UI activity and use Validation to debug the issue.
• If needed, re-indicate the element as its properties might have changed
• Use “Check state” activity to check the application state before executing the action
• Increase the “Delay before” value to allow time to the application to render entirely and become responsive

I was wondering if there is a way to make this exception message more specific, so we know which element was not found. Perhaps by including the activity title or Object Repository item name.

Another option would be to surround each activity with a try-catch and throw own exceptions, but this is not an ideal solution in my opinion.

Thanks!

Hi

This can be achieved only with a exception message statement like this

“Your own exception message” + “ at - “ + exception.Source.ToString

And again this can be achieved only when you define your exception message

Why not it is ofcourse a good a option and that’s why when exception handling comes
Try catch comes as the first activity to incorporate

And there are only threee ways to handle exception

  1. Try catch
  2. Retry scope
  3. Global exception handler

So with try catch and a Throw activity with own exception message like below will work for sure

New System.Exception(“your message”)

Or

New BusinessRuleException(“your message”)

Cheers @Senne_Symons

1 Like

Hi Palaniyappan,

Thanks for your feedback.

Why I want to prevent having to put try-catch scopes around each click, type into, etc. is because it increases the steps needed to develop a workflow, and it reduces the readability of the flow.

Also, in the case where an activity can give multiple different exception (UI element not found, or Verification failed), it would give out the same exception because we have overwritten it.

exception.Source.ToString gives me UiPath.UIAutomationNext.Activities, so not really useful when debugging.

In my opinion, it would be easier and better if the original exception message would include details about the activity/object where it went wrong.

have a check if the exception has also an innerException.

Then I would suggest you to try with Global exception handler
That would focus on all the activities and there you got a property to know the activity name where it got failed
Use the ActivityInfo property for errorInfo to get the name of the activity which threw the exception and view it in the Output panel.

For more info

Cheers @Senne_Symons

That Global Exception Handler looks useful, I used it before but did not know that this was one of the possibilities.
Is there a way to add that ActivityInfo to the Exception Message? Do we throw a custom exception from the Global Exception Handler and set result to ignore? Or what would be the correct way to do this?