Element Exists Else Skip

I have a foreach that deletes items from a GUI. When an item is not present in the GUI the sequence breaks. I of course want it to skip onto the next row in the item list. I have set up an Element Exists which detects whether the ‘delete’ element in present. I have this then going into an ‘IF’ but its doesn’t seem to skip.

Where do I go from here:

Hi @Andrew_Callaghan

You need to create a boolean variable in the Output of Element Exists activity
The replace the True value with the boolean variable

Thanks for your help @GreenTea. I’ve now added a Boolean variable (TruFal) without a default and put this into the Element Exists output. Do I need to add some logic here: image

Hi @Andrew_Callaghan

No additional logic needed since the variable TruFal is already a Boolean.

This doesn’t skip onto the next row. The element is definitely only present when the item exist in the GUI. I see the continue activity is supposed to send the process back to the ForEach but the flow just hangs without error


my apologies - there is an error
image

okay. i’m very sorry. closer examination of the html show’s the ID is still present. The delete button disappears by changing class image - I guess my question is then around how to specify class in the Element Exists’ activity

Hi @Andrew_Callaghan

Ok. You could try Image Exists in place of Element Exists activity. The Condition of If activity can be as simple as TruFal , without =True

Regarding the Element Exists or Image Exists activity, reduce the Timeout (milliseconds to 5000)

Hope this helps.

Thank you. I’m not sure i’ve set this right.


when I reverse it to False, I can see all the items in the list are flowing through and getting skipped. So I guess i’ve not configured the image properties correctly. It seems there image is generated by css

Hi @Andrew_Callaghan

Ok, I saw ImageFound is actually ImageExists. It is the same. Please Indicate Scope on Screen.
Sample image
image

Then expand the selector editor and launch UiExplorer.
Sample image

Finally you can change the selector properties to match the image properties

thank you. I did that but came out with the same selector. It seem the only thing that changes when the item isn’t present, is the button class.

Hi @Andrew_Callaghan

I see now. The only thing left is to assign TruFal to False inside Then block. This will reset TruFal Boolean value to False when the Delete button class cannot be detected. Thus the list will flow through and getting skipped. Hope this helps.

Thanks for putting up with me. I’m not sure what you mean ‘inside Then block’ ?

There is another element that shows text. Is the a way to read from this e.g when ‘Showing 0 of 0’ = False ?

I think he means that you should assign False to TruFal before each round of the loop. Before Element Exists, or right after the Sequence where you click the buttons (since here, TruFal is True).

But it does not really makes sense. I mean, if TruFal is True when you check if the “A delete” Element exists, and then there is no delete button, then TruFal would be False. So there is no need to “reset” the variable.

I solved a similar problem with the Get Attribute activity. The trick is to find the right names of the attributes:

If you open the current selector of the “Element Exists: delete button” in UiExplorer (you click the three lines and then Open in UiExplorer), you can have a look at the Property Explorer (in the bottom left corner). Maybe there is an attribute there which tells you which id the button is. Maybe the id itself, maybe the text which appears when you hover it, maybe something else.

You use Get Attribute to get the value here… That will probably be a string. And you can use this in your If statement, “If buttonID.Equals(“delete”) Then do …”

Maybe a Get Text? That sometimes work, sometimes not. You can use F4 to change the selector mode and try a few different variants. And then If textFound.StartsWith(“Showing 0 of 0”) Then do…

Thanks for the help @mar.svh - i’m now trying with the Get Text - with the if statement, should it look like this? image where textFound is the name of the string variable?

Yes, that was what I was meaning. It could be a good idea to put a breakpoint at the If block. Then you check the value of textFound at this point (in locals, usually on the left side in uipath studio). Sometimes, GetText takes more text than you think. Sometimes it takes nothing. It depends on the selector.

You can even use ‘Try Catch’. You can put a Try Catch inside ForEach. Keep the Click activity in Try Block. if the element is not found, it will jump to Ctach Blck. (leave the Ctach Block empty)…Further, it will repeat the same process until item is present.