How to stop While activity for Element Exists

Hi all,

I used a While activity for my data scraping. I added an Element Exists activity before the while activity. I created a variable for the EE as Check.

So in my While activity, my condition is Check = True.

The element by the way is a next button. So, my While activity or loop won’t stop because the EE finds the element as True all the time. The problem here is the next button is already greyed out or not clickable because we are already on the last page. However, Element Exists can’t understand that. It can see the button but not clickable but still EE will still return True. How do I stop this loop so I can just proceed to my Write Range activity?

Hello @jjtubon,

Please compare selectors for the button when it is grayed and when not grayed.
You should be able to find a css class name or something that indicates the current state of the button that will help differentiate the states of the button.

Therefore, your Robot must look for both types of elements and then use these two elements to validate the Check variable

Theoretically:

eeButton = FindElement(selector for regular button) ' if found will return true
eeGrayButton = FindElement(selector for Gray button) ' at the same time this will be false

When the Button Grays out, the above condition will be reversed.

Check = (eeButton IsNot Nothing)  'Good, continue with Loop
Check = (eeGrayButton IsNot Nothing ) 'No, stop while loop

You can combine these two conditions into an Or and see how it works.

thanks

Thanks for giving me such a detailed solution. I will try and figure this out. I am not familiar with coding yet. I am only doing drag and dropping with StudioX Community.

Sorry that is not code.

It is pseudo-code that represents the Find Element Activities and the Assign Activities (for the Check variable)

You got to build that in Studio.

thanks

Got it.

Quick question. Did you suggest to use FindElement or just use Element Exists?

I am about to use ElementExists now with this condition.

CheckRegBtn = True Or CheckGreyBtn = True
Is that correct?

I use Find Element as regular practice. I find it easier to understand because I am trying to find something on a page without pre-determining if it exists or not.

You can write it both ways and contribute your findings here. It would help us all. :slight_smile:

I just tried two Element Exists before the While.

First EE is CheckRegBtn and second EE is CheckGreyBtn

I added on the While condition as CheckRegBtn = True Or CheckGreyBtn = True
also tried Reg = True Or Grey = False

They are still looping nonstop. I will try Find Element now

FindElement is a UiElement data type. Can’t use True or False. I am more confused now.

Yep you have to use a condition in the Assign activity

Check = CheckGreyButton Isnot Nothing

It will return a true or false value for this condition depending on whether the CheckGrayButton is a valid UiElement.

1 Like

Wait. So you used the variable name Check. Is that the first Element Exists? And CheckGreyButton is the second Element Exists?

If so, that means Regularbutton = Greybutton Isnot Nothing?

One has to be true and the other has to be false. How can the button exist as Grey and not Grey at the same time?

I guess that is one way to write the condition .

First Element Exists variable name is Check
Second Element Exists variable name is CheckGreyBtn
Both EEs are in Scope: Main

Under While activity condition: Check = CheckGreyBtn Isnot Nothing

It’s an error

Please

Initialize Check to True before beginning while loop

Then use the Check variable in the While condition

Inside the While loop:

use “Assign” Activity to set the condition for the Check variable based on which element you find.

I am not sure of what I am doing.

image

I’m not 100% sure, but I think Check App State can replace Find Element and Element Exists in many cases.

Check App State has a boolean Result and includes “Target Appears” and “Target Does Not Appear” boxes by default.

Correct, but you are checking if CheckGreyBtn UiElement is a valid object or not. Not whether it is True or not.

Going back to this line:

Check = (CheckGreyBtn IsNot Nothing) . This will return true if your button element is valid.

Try this just for the kicks by setting CheckGreyBtn to Nothing

CheckGreyBtn = Nothing
Check = (CheckGreyBtn IsNot Nothing) . This time the result returned is False because you have intentionally destroyed the UiElement.

Hope this helps