Ask a Question

Reliable way of performing action if element exists without failing if it doesn't

SOLVED
LoneWanderer04
Occasional Contributor

Reliable way of performing action if element exists without failing if it doesn't

Hello everybody!

 

This is my first time I've really used TestComplete as the main test engine, with my previous background being in Selenium.  When I used that, if I needed to do an action on an element that might or might not exist (like closing a window if displayed first), I'd just do a simple "if all(*element identifier*).length > 0" or something similar, which would give me a 0 if it didn't exist, and greater if it did, so it wouldn't fail out.

Is there some similar way in TestComplete to basically have a basic check to see if an element is present so I can do an action if it is, and just ignore the next code if it isn't?  I've tried FindElement, WaitChild, etc, and all those don't seem to be doing quite what I expected.

1 ACCEPTED SOLUTION

Accepted Solutions
Marsha_R
Community Hero

Re: Reliable way of performing action if element exists without failing if it doesn't

https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/waiting-process-or-window-a...

 

There are some examples here of how to wait for an object or a process and then execute code conditionally after that.  

Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame

View solution in original post

2 REPLIES 2
Marsha_R
Community Hero

Re: Reliable way of performing action if element exists without failing if it doesn't

https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/waiting-process-or-window-a...

 

There are some examples here of how to wait for an object or a process and then execute code conditionally after that.  

Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame

View solution in original post

LoneWanderer04
Occasional Contributor

Re: Reliable way of performing action if element exists without failing if it doesn't

I ended up combining the concepts of that page, but I needed to check a specific property instead of a general element like that article says.

Exists wasn't working, since the element was always existing, so I had to grab an element like they explained, then check for a calculated style on the element's parent for a specific field that changed. That seems to work.

cancel
Showing results for 
Search instead for 
Did you mean: