cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Highlighted
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
Highlighted
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.  

View solution in original post

2 REPLIES 2
Highlighted
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.  

View solution in original post

Highlighted
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.

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors