pub fn parse_elements(xml: &str, interactive_only: bool) -> Vec<UiElement>Expand description
Parse uiautomator XML into a flat list of UI elements.
If interactive_only is true, only elements that are clickable, focusable,
scrollable, or checkable are included, plus non-interactive elements that
have visible text or content descriptions (as landmarks for orientation).
Each element gets a sequential index (starting at 1) and pre-computed center coordinates for easy tapping.
ยงExamples
use adbridge::screen::elements::parse_elements;
let xml = r#"<?xml version="1.0" encoding="UTF-8"?>
<hierarchy rotation="0">
<node text="Login" resource-id="com.app:id/btn" class="android.widget.Button"
clickable="true" focusable="true" bounds="[200,700][880,800]" />
<node text="" resource-id="com.app:id/spacer" class="android.view.View"
clickable="false" focusable="false" bounds="[0,800][1080,810]" />
</hierarchy>"#;
// interactive_only filters out non-interactive, unlabeled elements
let elements = parse_elements(xml, true);
assert_eq!(elements.len(), 1);
assert_eq!(elements[0].text, "Login");
assert_eq!(elements[0].center, (540, 750));
assert!(elements[0].clickable);
// All mode includes every element with valid bounds
let all = parse_elements(xml, false);
assert_eq!(all.len(), 2);