# Find function with retries

**URL:** <https://community.smartbear.com/t/find-function-with-retries/346>\
**Category:** TestComplete\
**Tags:** test, testcomplete, migrated\
**Created:** [January 15, 2025, 8:37pm UTC](https://community.smartbear.com/t/find-function-with-retries/346 "2025-01-15T20:37:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [January 15, 2025, 8:37pm UTC](https://community.smartbear.com/t/find-function-with-retries/346/1 "2025-01-15T20:37:42Z")

</div>

> Originally posted by **pse** on January 15, 2025

Hi,

I am trying to design a function for object recognition that allows for retries. Here is my code snippet below:

def wait\_for\_object\_with\_retries(base\_object, find\_properties, find\_values, depth):  
attempt = 1  
while attempt \<= retry:  
try:  
base\_object.Refresh()  
#base\_object.RefreshMappingInfo()  
reference\_object = None  
reference\_object = base\_object.Find(find\_properties, find\_values, depth)  
if not reference\_object.Exists:  
raise Exception(“Object not detected.”)  
return reference\_object  
except Exception as e:  
Log.Message(str(e))  
Delay(1000, “Unable to find object. Waiting for timeout.”)  
attempt = attempt + 1  
return None

For whatever reason, the Find function’s ability to find an object given parameters is inconsistent. When something is looked for right before it appears, the code attempts to retry two more times. However, even if the new object is demonstrably on screen, the retry has the same result of not finding the object. Any recommendations?

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [January 15, 2025, 9:20pm UTC](https://community.smartbear.com/t/find-function-with-retries/346/2 "2025-01-15T21:20:53Z")

</div>

> Originally posted by **JDR2500** on January 15, 2025

Hmm, looks good to me. I gather you are confident in the validity of the parameters you’re passing the function. Maybe try FindChild?

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [January 15, 2025, 9:23pm UTC](https://community.smartbear.com/t/find-function-with-retries/346/3 "2025-01-15T21:23:55Z")

</div>

> Originally posted by **Hassan\_Ballan** on January 15, 2025

Not sure if any of my suggestions will help.

If you are using NameMapping, TestComplete rely heavily on caching and you will need to use the RefreshMappingInfo for that specific object, it’s parent, or starting from the tree top Browser.

Maybe you can try to split to two functions, one that will loop and check if exist, and to call the other function that refresh and find.

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [January 16, 2025, 9:31am UTC](https://community.smartbear.com/t/find-function-with-retries/346/4 "2025-01-16T09:31:02Z")

</div>

> Originally posted by **rraghvani** on January 16, 2025

What is the intended purpose of this function?

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [January 22, 2025, 6:23pm UTC](https://community.smartbear.com/t/find-function-with-retries/346/5 "2025-01-22T18:23:38Z")

</div>

> Originally posted by **pse** on January 22, 2025

The goal is to find an object again if it is not found immediately. For example, if an object didn’t exist when the function is called, but appears within 3 seconds, the function needs to be able to find the object now that it has appeared.

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [January 22, 2025, 7:53pm UTC](https://community.smartbear.com/t/find-function-with-retries/346/6 "2025-01-22T19:53:29Z")

</div>

> Originally posted by **Marsha\_R** on January 22, 2025

There are built in functions for waiting for objects

> **[Waiting for an Object, Process or Window Activation | TestComplete Documentation](https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/waiting-process-or-window-activation.html)**
>
> Create and run automated tests for desktop, web and mobile (Android and iOS) applications (.NET, C#, Visual Basic .NET, C++, Java, Delphi, C++Builder, Intel C++ and many others).

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [January 22, 2025, 8:11pm UTC](https://community.smartbear.com/t/find-function-with-retries/346/7 "2025-01-22T20:11:15Z")

</div>

> Originally posted by **scot1967** on January 22, 2025

> Have you tried using FindEx or FindChildEx? This will build your delay into the method and simplify your code! It also has a ‘refreshtree’ option you can enable to ensure you can find objects that are dynamically created and cause a problem with the traditional find method.
> 
> [https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/findex-method.html?sbsearch=FindEx%20method](https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/findex-method.html?sbsearch=FindEx%20method)

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [January 23, 2025, 10:01am UTC](https://community.smartbear.com/t/find-function-with-retries/346/8 "2025-01-23T10:01:30Z")

</div>

> Originally posted by **rraghvani** on January 23, 2025

One of my replies is missing!

If you refer to [https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/waiting-process-or-window-activation.html](https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/waiting-process-or-window-activation.html) mainly Using WaitNNN Methods. There are methods to wait for an object to appear within a given time.

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [October 7, 2026, 5:15pm UTC](https://community.smartbear.com/t/find-function-with-retries/346/9 "2026-10-07T17:15:48Z")

</div>

Closed on October 7, 2026, 5:15pm UTC

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
