How can I catch the "Attach Window: Could not find the UI element corresponding to this selector" exception?

Friends,

Sometimes my process runs into an invalid URL. I get the “Attach Window: Could not find the UI element corresponding to this selector” message.

How can I embed the Attach Window activity in a Try/Catch activity, so as to skip invalid URLs?

I have tried the SelectorNotFound exception unsuccessfully, see the xaml file attached.
image
Catch_404_exception.xaml (11.9 KB)

Hi @mangogul

Use the element exist activity inside the attach window, if the element is not appears then the output of element exist is Boolean. After that place If condition which boolflag = false then give the throw activity in then block. In throw write the business expection.
New BusinessRuleException(“URL is invalid”)

It throws the business exception with the message.

Hope it helps!!

@mangogul

It does go into the catch block

once error is throw just use step into and check…

cheers

Hi Mahesh,

thanks! Unfortunately, the exception is thrown before the Element Exists activity can determine whether the expected content is present.

Set it to System.Exception so it’ll catch anything. Force the kind of error you are trying to handle. In a Log Message put exception.GetType and then you’ll be able to see the exact exception type. Then you can change the catch to that exception type.

That being said, it’s better to manually check if the page loaded correctly, using Check App State. Use it to look for a page element that indicates the page successfully loaded. In the “does not appear” block Throw your own Business Exception (invalid URL provided).

Okay @mangogul

You have already encapsulated the attach window activity with Try catch activity. If any exception is thrown by the activity weather it is business or system exception it will catch in the catch block. In the Catch block you can give the log message to print the exception in the Output panel.

In the log message give like this
Exception.message to know the error.
Exception.Source to print the location of the activity which throws the error.
image

Hope you understand!!

@postwick , @mkankatala , @Anil_G , thanks for your help!

Unfortunately, I can’t manage to catch the 404 error when an invalid URL is fed to the process. The Open Browser activity is in the catch, but the process is interrupted nonetheless. So I can’t, for example, perform an Element Exist activity if the website doesn’t exist in the first place.

If I put, in this example, the faulty input field into the catch it works as expected if the URL is correct (see the alternative “exception handling as expected” flow in
validate site url.xaml (18.2 KB)
).
But I don’t see how to catch the Open Browser or Attach Window activities if the URLs are not correct.
What am I missing?

You don’t look for the invalid URL. The first activity inside the Open Browser should be a Check App State that looks for a page element that indicates the page successfully loaded.

Also you should be working in modern, using the newer better activities Use Application/Browser, Check App State, etc.

@mangogul

Idea is like this…manually would you understand a url is correct or wrong by looking at url? no

so even through automation after opening url…you have to check for something that you would expect or some error message so that if required is found page is loaded…or if error is found can throw error…either ways you can know…so a element exists or check app state is needed

cheers

please elaborate more on this as we can check the status code of a HTML request

Hi @ppr , HTTP request is indeed the solution.

So, I learned that I can’t catch 404 errors per see, but I would rather have to check in advance (see Check Href link exists or not - #2 by arivu96).

Hi Paul, I don’t find those modern activities. Are they in the StudioX environment? I have created my application some years ago, so I seem to have missed some new developments.

Oh, you have your post marked as Studio, not StudioX.

Go to your project settings and see if there is a “modern” setting. This is what it looks like in Studio:

1 Like

Hi Paul,
thank you, got it. I will try it out.
Best regards
Christoph

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.