adb_view_tree

class adb_view_tree.AdbViewTree(adb: ~adb_tool_py.adb_command.AdbCommand = <adb_tool_py.adb_command.AdbCommand object>)[source]

Bases: object

A class to capture and interact with the UI hierarchy of an Android device.

capture() None[source]

Captures the current UI hierarchy of the connected Android device.

check_resource_id(resource_id: str, index: int = 0, root_node: UINode = None, is_capture: bool = False) bool[source]

Checks if a node with the specified resource-id exists.

Parameters:
  • resource_id – The resource-id to search for.

  • index – The index of the matching node to return, defaults to 0.

  • root_node – The root node to start the search from, defaults to None.

  • is_capture – Whether to capture the UI hierarchy before searching, defaults to False.

Returns:

True if the node exists, False otherwise.

check_text(text: str, index: int = 0, root_node: UINode = None, is_capture: bool = False) bool[source]

Checks if a node with the specified text exists.

Parameters:
  • text – The text to search for.

  • index – The index of the matching node to return, defaults to 0.

  • root_node – The root node to start the search from, defaults to None.

  • is_capture – Whether to capture the UI hierarchy before searching, defaults to False.

Returns:

True if the node exists, False otherwise.

content: str = None
content_tree: UINode = None
find_node(attribute_name: str, search_text: str, index: int = 0, root_node: UINode = None, is_capture: bool = False) UINode[source]

Finds a node by the specified attribute.

Parameters:
  • attribute_name – The attribute name to search by.

  • search_text – The text to search for.

  • index – The index of the matching node to return, defaults to 0.

  • root_node – The root node to start the search from, defaults to None.

  • is_capture – Whether to capture the UI hierarchy before searching, defaults to False.

Returns:

The matching UINode.

find_nodes(attribute_name: str, search_text: str, root_node: UINode, is_capture: bool = False) list[UINode][source]

Recursively finds all nodes with the specified attribute.

Parameters:
  • attribute_name – The attribute name to search by.

  • search_text – The text to search for.

  • root_node – The root node to start the search from.

  • is_capture – Whether to capture the UI hierarchy before searching, defaults to False.

Returns:

A list of matching UINodes.

find_resource_id(resource_id: str, index: int = 0, root_node: UINode = None, is_capture: bool = False) UINode[source]

Finds a node by its resource-id attribute.

Parameters:
  • resource_id – The resource-id to search for.

  • index – The index of the matching node to return, defaults to 0.

  • root_node – The root node to start the search from, defaults to None.

  • is_capture – Whether to capture the UI hierarchy before searching, defaults to False.

Returns:

The matching UINode.

find_text(text: str, index: int = 0, root_node: UINode = None, is_capture: bool = False) UINode[source]

Finds a node by its text attribute.

Parameters:
  • text – The text to search for.

  • index – The index of the matching node to return, defaults to 0.

  • root_node – The root node to start the search from, defaults to None.

  • is_capture – Whether to capture the UI hierarchy before searching, defaults to False.

Returns:

The matching UINode.

touch_resource_id(resource_id: str, index: int = 0, root_node: UINode = None, is_capture: bool = False) bool[source]

Simulates a tap on the node with the specified resource-id.

Parameters:
  • resource_id – The resource-id to search for.

  • index – The index of the matching node to return, defaults to 0.

  • root_node – The root node to start the search from, defaults to None.

  • is_capture – Whether to capture the UI hierarchy before searching, defaults to False.

Returns:

True if the tap was successful, False otherwise.

touch_text(text: str, index: int = 0, root_node: UINode = None, is_capture: bool = False) bool[source]

Simulates a tap on the node with the specified text.

Parameters:
  • text – The text to search for.

  • index – The index of the matching node to return, defaults to 0.

  • root_node – The root node to start the search from, defaults to None.

  • is_capture – Whether to capture the UI hierarchy before searching, defaults to False.

Returns:

True if the tap was successful, False otherwise.