Hello, I am trying to create an automated test to check if an element exists.
My test is something like this: if the element exists then: click the button, else: execute specific steps. The test never reaches the “else” condition, it remains stuck there…
There is a screenshot. As you can see I am using a boolean condition in order to check the existence of that element.
Anyone could help? Thank you!
Hi
Welcome to uipath community
It seems like that element exists always may be that’s why the Boolean being return as True and it gets into THEN part
Kindly ensure that The element is not there
Or
We can try with IMAGE EXISTS activity and choose that image which would give us Boolean value either
Kindly try this and let know for any queries or clarification
Cheers @Roberto_State
Hello, thank you for the warm welcome! From my point of view, when I run the test, it doesn’t seem like that. When I have the element on screen, the activity gets into then part but if the element doesn’t exist, then the activity doesn’t do anything, doesn’t enter then or else parts anyhow.
There must be two chances
Like either the element exists doesn’t work when the element is not there and mostly it won’t fail
So the next one we need to validate is the part inside the else part
That in else part keep a log message activity as a first activity where mention a string like “entered else part” and then the current attach window activity
We can validate from output panel that if that log message appears then it has entered the else part but the next set activities didn’t get executed
So at that stage we need check with sequence in else part
Cheers @Roberto_State
I’ve tried to test if the activity enters the “else” clause by using an assign and write line and it seems it doesn’t even reach that point.
Also, I’ve tried with Image Exists and I have the same behavior. In every case the test refuses to enter the THEN clause
Earlier it was mentioned like it didn’t enter the ELSE part when element exists was used
So at that time did the process get into THEN part
Cheers @Roberto_State
Hi Roberto,
Did you try printing the output result of element exists when the image does not exist ?
How do I do that? I’m new with this program.
@Palaniyappan It was a misunderstood, I said earlier that the program doesn’t enter any part if the element doesn’t exist. The problem with my test is that when the boolean returns false, it doesn’t reach the else part
Hmm
I hope there is problem with variable mentioned
Because by default the Boolean variable will be with false value and it will enter atleast the else part
Fine
—make sure once that the output variable in element exists and in if condition both are same
—then we can validate the output of element exists with a writeline activity like this
Booleanvariable.ToString
So that we can check whether it true or false in the output panel
Then based on that we need to check which side it should go and we need to check the activities inside that part either THEN or ELSE
cheers @Roberto_State
After the element exists activity and before if else activity , could you please try doing write line of booleanUIElementExists1.ToString in both the cases when image is existing and not
The line returned True even if the image is not present. Hmm
Yeah, seems like there is a problem with the boolean variable, it returns true even if the element or image is not present
Which means element exists is not working in this case
Have you assigned the default value of the boolean variable to true ?
Other solutions: if it is a image, try image exists , or try using find element . In case of only validation purpose if both of the above are not working try to find any other stable element in the page .
Tried multiple default variable assignations, with default true value, the program returns true and if I set it to False (as default value) the program will, again, return True.
I’ve noticed that if I use element exists activity, the program will remain stuck there, trying to find that element in order to advance, because my write line doesn’t return anything.
Try using other suggested activities in that case
Can I put a timeout on that activity, I mean…to look for an element and if it doesn’t find it in 2 seconds to go to the next step. Because it looks that the program is struggling in finding the element, without going any further.
Depends on the business requirement , because if element exists is not working , I dont see it’s use here ,Could you please explain exactly what you are trying to do with element exists
Tried with multiple elements and I got the same result…
UPDATE: I’ve waited the program to finish (took a little) and finally reached the “THEN” part, but it took way too long, because the element exist activity takes a while in looking for my button. Seems like it works now, I only need a way to shorten the time of element exist activity.
Try to enhance the selector
I’ve found the solution. Thank you guys! The problem was with the timeout, which took too long in the case of boolean returning false. So I’ve set the timeout of element exist activity to 500 milliseconds and it’s just running perfectly.