import squish import test import object def get_object_from_names(names_dict, error_message = "Missing object", timeout_ms = 200): """ To get an object with try..except catching to prevent script errors when the object is not found on the GUI @param names_dict - the dictionary element from the names.py file (ie: names.some_variable_name_of_element) @returns the object with corresponding dictionary, otherwise "None" """ try: return squish.waitForObject(names_dict, timeout_ms) except LookupError: test.fail("ERROR : " + error_message) return None def setObjectText(obj, text): obj["text"] = text return obj def findObjectById(parent, id): """ Recursively searches for a child object by its id. Returns the found object or None if not found. """ if str(parent.id) == id: return parent for child in object.children(parent): found = findObjectById(child, id) if found: return found return None def findChildByText(parent_object, target_text): """Recursively finds a child object by its text property.""" for child in object.children(parent_object): if hasattr(child, "text") and str(child.text) == target_text: return child found = findChildByText(child, target_text) if found: return found def findAllObjectsById(parent, target_id): """ Recursively finds all child objects by their id property. Returns a list of all matching objects found. """ results = [] # Use hasattr to safely check for 'id' property if hasattr(parent, 'id') and str(parent.id) == target_id: results.append(parent) # Recurse through all children to collect all instances for child in object.children(parent): results.extend(findAllObjectsById(child, target_id)) return results def findAllObjectsByText(parent, target_text): """ Recursively finds all child objects that have a 'text' property matching the target_text. Returns a list of matches. """ results = [] # Use hasattr to safely check for 'text' property before comparing if hasattr(parent, 'text') and str(parent.text) == target_text: results.append(parent) # Recurse through all children for child in object.children(parent): results.extend(findAllObjectsByText(child, target_text)) return results