MCPcopy Index your code
hub / github.com/TencentQQGYLab/AppAgent / get_id_from_element

Function get_id_from_element

scripts/and_controller.py:41–53  ·  view source on GitHub ↗
(elem)

Source from the content-addressed store, hash-verified

39
40
41def get_id_from_element(elem):
42 bounds = elem.attrib["bounds"][1:-1].split("][")
43 x1, y1 = map(int, bounds[0].split(","))
44 x2, y2 = map(int, bounds[1].split(","))
45 elem_w, elem_h = x2 - x1, y2 - y1
46 if "resource-id" in elem.attrib and elem.attrib["resource-id"]:
47 elem_id = elem.attrib["resource-id"].replace(":", ".").replace("/", "_")
48 else:
49 elem_id = f"{elem.attrib['class']}_{elem_w}_{elem_h}"
50 if "content-desc" in elem.attrib and elem.attrib["content-desc"] and len(elem.attrib["content-desc"]) < 20:
51 content_desc = elem.attrib['content-desc'].replace("/", "_").replace(" ", "").replace(":", "_")
52 elem_id += f"_{content_desc}"
53 return elem_id
54
55
56def traverse_tree(xml_path, elem_list, attrib, add_index=False):

Callers 1

traverse_treeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected