How to skip past an empty element?

I am using the Get Text activity to get attachment file names from a web application. Sometimes those files aren’t attached. Which is fine, the filename value can be null.

I used ContinueOnError to get past the issue of the activity being unable to find an on-screen element. This is obviously a slow solution, the program waits 30 seconds to timeout before moving to the next.

Is there a way for UiPath to recognize that there is no element and then skip ahead to the next activity? If not, is there at least a way to limit the amount of time spent so it times out after 8-10 seconds instead of 30?

Thanks!

You can change the TimeoutMS property lower. You can use 3000 or 5000 depending on how long it takes to load the element. If you can assume that it is already loaded then use 0, so it checks instantly.

Then, the trick is to look at the right element so it can detect the attachment or no attachment in the quickest time. So, you may consider the Element Exists activity to wait until the page is in a loaded state, then use 0 timeoutMS to look for the attachment, else look for the no attachment.

Hope that helps.

Regards.

1 Like

So if I just place the Element Exists activity prior to the Get Text activity and set Get Text to zero then I’m good to go?

Do I need to use the output variable from Element Exists?

Element Exists of element A followed by Get Text of element A is the same thing as just using Get Text of element A by itself. This is because both methods wait until element A is there to get the text.

So you need to be a little more strategic.

I would recommend considering these ideas:

Idea 1: Element Exists of element A using the Output property and a slight timeout. Check if the boolean is True, then Get Text of element A using a timeout of 0. If boolean is False then, Element Exists of element B using the Output property and timeout of 0 (since page is already loaded at this point). Check if this boolean is true, then perform tasks due to element B. If boolean is False then, extraction could not occur so log accordingly (or Throw exception if needed to retry).

Disadvantage: Slight delay when element A is not there and instead element B is there, because first Element Exists is waiting for element A.

Idea 2: Same as Idea 1, except start with another Element Exists to look for another element that identifies the page is loaded and ready to be interacted with. This would eliminate the slight delay, but to be honest the delay would not be much anyway (depends on how the application loads though)

Disadvantage: The page could load at different rate as elements or there is nothing to identify that it is ready to be interacted with.

Hope this helps.

So use Element Exists as a strategic way to navigate and make decisions throughout the application.

Regards.

1 Like

Thanks @ClaytonM , I appreciate you breaking down the disadvantages of each approach. Very helpful for learning.

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