FIx corner cases (val connection in chrome when using playwright, and action parsing for agent, and accessibility tree xml handling)
This commit is contained in:
@@ -3,8 +3,11 @@ import xml.etree.ElementTree as ET
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
|
||||
def find_leaf_nodes(xml_file_path):
|
||||
root = ET.fromstring(xml_file_path)
|
||||
def find_leaf_nodes(xlm_file_str):
|
||||
if not xlm_file_str:
|
||||
return []
|
||||
|
||||
root = ET.fromstring(xlm_file_str)
|
||||
|
||||
# Recursive function to traverse the XML tree and collect leaf nodes
|
||||
def collect_leaf_nodes(node, leaf_nodes):
|
||||
@@ -97,19 +100,3 @@ def draw_bounding_boxes(nodes, image_file_path, output_image_file_path):
|
||||
|
||||
# Save the result
|
||||
image.save(output_image_file_path)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
with open('chrome_desktop_example_1.xml', 'r', encoding='utf-8') as f:
|
||||
xml_string = f.read()
|
||||
image_file_path = 'screenshot.png' # Replace with your actual screenshot image path
|
||||
output_image_file_path = 'annotated_screenshot.png' # Replace with your desired output image path
|
||||
|
||||
leaf_nodes = find_leaf_nodes(xml_string)
|
||||
filtered_nodes = filter_nodes(leaf_nodes)
|
||||
print(f"Found {len(filtered_nodes)} filtered nodes")
|
||||
|
||||
for node in filtered_nodes:
|
||||
print(node.tag, node.attrib)
|
||||
|
||||
draw_bounding_boxes(filtered_nodes, image_file_path, output_image_file_path)
|
||||
|
||||
Reference in New Issue
Block a user