Element exists = Wait element appear?

Hey,

Quick question. I noticed there’s a “Wait element vanish” activity, but no “Wait element appear” activity.

However, the “Element exists” activity waits x amount of milliseconds and throws an error if the desired element still is not visible after that time.

Can this be used to, essentially, wait for elements to appear within the allotted time and catch exceptions if they don’t? Or am I perhaps missing something?

Thanks!

1 Like

Hi there @trog,
You are absolutely correct in your thinking.

As part of our standards, we will frequently use an ‘Element Exists’ activity to check pre/post conditions for a given component.

One quick note, however, the activity itself will not throw an exception, it will simply timeout.

But, it will output a Boolean value, which can be used to throw an exception, if required.

Please let me know if you have any further queries.

Thanks in advance,
Josh

7 Likes

hi @trog

As a note to Josh’s comments. You could use a find element activity to wait for the element to appear this has a default 30second timeout after which it will throw an error.

Element exists is great for things like popup boxes that may or may not appear and need to be handled when they do appear.

Find Element is useful for when a page may take some time to load but varies so a delay will either be too short or too long to use.

Hope this helps.

5 Likes

Hi @trog, When you absolutely want to wait for an element to appear, we have used the element exists in a do while loop. The condition is set to run when it sees the element appear. If it does not appear in each loop it continues to wait. You can also put in a counter and loop a certain number of times.

1 Like

Hi @trog,
We have a Activity called “On Element Appear”
This activity continue the flow after when the mentioned element appear on screen
else wait for particular time what we mentioned in TimeOutMS. after that it throwing error. This activity may be satisfying your requirement.
it quite similar to "wait element appear "
Regards,

3 Likes

Thanks for all the answers!

The purpose is as follows: I want to check if a page has loaded properly. If it hasn’t loaded within the designated timeout, an exception should be thrown and caught and the robot can go into recovery mode (kill all iexplore processes and try again). The entire flow is surrounded with a try-catch.

@Mr_JDavey You’re right. The description for the “Element Exists” timeout is misleading (this might be something for the UiPath team to change). It says an error is thrown when it times out, but I just discovered this is not actually the case. The flow continues anyway, even if you leave the output field blank.

@jakelewis18 This is exactly what I was looking for, thank you! This activity does throw an error when the element isn’t found. Time to adjust my code. :upside_down_face: @Mr_JDavey this might be interesting for you as well. Using Element Exists and then an if statement to check the boolean value and decide if you want to throw an exception is a lot more work, depending on your requirements Find Element might be easier.

1 Like

Hi there @trog,
These are excellent points and I am aware of ‘Find Element’, but generally we prefer to throw bespoke messages upon failing to locate an element.

Otherwise, I do not see the advantages of using ‘Find Element’ over modifying the default timeout included for activities such as ‘Click’/‘Type Into’, as these will throw in much the same way.

Unless, of course, you required the UiElement for further functionalities.

Thanks,
Josh

3 Likes

@Mr_JDavey Interesting. So you are saying I can skip Find Element entirely and rely on exceptions thrown by the click/type activities to determine if a page has loaded or not?

I make generous use of logging and the exception thrown by activities when an element is unavailable includes the selector of the element that wasn’t found. For me, this is sufficient for debugging purposes. But if my usage of Find Element is redundant that would make things even simpler! :slight_smile: Will try this out.

Hi there @trog,
Obviously, this comes down to personal preference, however, if you intend on throwing the standard exception, using ‘Find Element’ beforehand seems a little pointless, as the ‘Click’/‘Type Into’ will simply throw itself.

Thanks,
Josh

3 Likes

Good points by @Mr_JDavey

Generally, Element Exists does not work well for waiting for elements to appear, but is useful to perform actions based on that element. You would need to put it inside a Do while (or Flow Chart loop) in order to use it as a wait machine which then also requires an exit to avoid infinite loops. I have recently used Element Exists to close all windows of a given selector, so it loops until the Element is no longer found.

The wait methods I use the most are with Retry Scope or Find Element

Find Element works well because the TimeoutMS let’s you wait until it shows up and fails if it never shows up. Then, you can also use the element variable to perform an action on it.

Retry Scope is useful, cause it can be used like a loop that has a built in exit (retry count). So you can try to click on a button but if it’s not available yet and gives you an exception, it will try again after a second.

Regards

6 Likes

Hi :slight_smile:

Say you want to do stuff on the page when it has loaded, for example Click, then you can tell Click to wait until ‘Complete’ instead of ‘Interactive’, which will wait for the whole app to be loaded until it will do the Click. If it were set on Interactive it would click when the UiElement was interactive, even though the rest of the page was not ready. Then you can set the timeout to whatever you want and get an exception.

3 Likes

Thank you for all the answers. If non-specific exceptions are required I don’t even need to look for elements as the click/type etc activities will do this for me. If a specific exception is required, the Element Exists activity can be used with an if statement to throw an exception.

2 Likes

Hi,

I am trying to read user input data from an excel and providing each row data into a web application form and registering the user.
Now want to validate if the data got saved successfully or not, by using ‘Find Element’ , and saving to excel file
I have selected the pop up window message to validate the Find Element, but can see that every entry are getting saved as ‘save’ however few contains wrong input also.

sharing the file.
can anyone please help, i suppose i am missing some validation in Find Element.
trycatch.zip (30.9 KB)

you should try retry scope activity

Hi. Is there a way to modify the time of exists activity ? Not to throw an error, just to wait less time if the image or the text does not appear

You can use this and set desired timeout on Find Element:
image
image

Hi @trog

Some important notes about your question:

  1. Element Exist will not throw exception if the element does not exist (selector cannot find the element). Instead, the activity returns a Boolean type variable as a result (True or False) Element Exist Activity Guide
  2. Find Element throws exception if the element does not exist and the Timeout exceeded, in other words, if the specified UI element does not appear within the specified timeout. Find Element Activity Guide

In the below image, I have tried to visualize the @jakelewis18 reply. Hope it will help