Find function with retries
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?