-
-
Notifications
You must be signed in to change notification settings - Fork 366
Add supports for Accessibility domain #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
j0j1j2
wants to merge
2
commits into
autoscrape-labs:main
Choose a base branch
from
j0j1j2:feat/impl-accessibility-domain
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+938
−0
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,225 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING, Optional | ||
|
|
||
| from pydoll.protocol.accessibility.methods import ( | ||
| AccessibilityMethod, | ||
| GetAXNodeAndAncestorsParams, | ||
| GetChildAXNodesParams, | ||
| GetFullAXTreeParams, | ||
| GetPartialAXTreeParams, | ||
| GetRootAXNodeParams, | ||
| QueryAXTreeParams, | ||
| ) | ||
| from pydoll.protocol.base import Command | ||
|
|
||
| if TYPE_CHECKING: | ||
| from pydoll.protocol.accessibility.methods import ( | ||
| DisableCommand, | ||
| EnableCommand, | ||
| GetAXNodeAndAncestorsCommand, | ||
| GetChildAXNodesCommand, | ||
| GetFullAXTreeCommand, | ||
| GetPartialAXTreeCommand, | ||
| GetRootAXNodeCommand, | ||
| QueryAXTreeCommand, | ||
| ) | ||
| from pydoll.protocol.accessibility.types import AXNodeId | ||
|
|
||
|
|
||
| class AccessibilityCommands: | ||
| """ | ||
| Implementation of Chrome DevTools Protocol for the Accessibility domain. | ||
|
|
||
| This class provides commands for interacting with the accessibility tree, | ||
| enabling inspection and querying of accessible nodes on a page. | ||
|
|
||
| See https://chromedevtools.github.io/devtools-protocol/tot/Accessibility/ | ||
| """ | ||
|
|
||
| @staticmethod | ||
| def disable() -> DisableCommand: | ||
| """ | ||
| Disables the accessibility domain. | ||
|
|
||
| Returns: | ||
| DisableCommand: CDP command to disable the accessibility domain. | ||
| """ | ||
| return Command(method=AccessibilityMethod.DISABLE) | ||
|
|
||
| @staticmethod | ||
| def enable() -> EnableCommand: | ||
| """ | ||
| Enables the accessibility domain which causes AXNodeIds to remain | ||
| consistent between method calls. | ||
|
|
||
| Returns: | ||
| EnableCommand: CDP command to enable the accessibility domain. | ||
| """ | ||
| return Command(method=AccessibilityMethod.ENABLE) | ||
|
|
||
| @staticmethod | ||
| def get_partial_ax_tree( | ||
| node_id: Optional[int] = None, | ||
| backend_node_id: Optional[int] = None, | ||
| object_id: Optional[str] = None, | ||
| fetch_relatives: Optional[bool] = None, | ||
| ) -> GetPartialAXTreeCommand: | ||
| """ | ||
| Fetches the accessibility node and partial accessibility tree for this | ||
| DOM node, if it exists. | ||
|
|
||
| Args: | ||
| node_id: Identifier of the node to get the partial accessibility | ||
| tree for. | ||
| backend_node_id: Identifier of the backend node to get the partial | ||
| accessibility tree for. | ||
| object_id: JavaScript object id of the node wrapper to get the | ||
| partial accessibility tree for. | ||
| fetch_relatives: Whether to fetch this node's ancestors, siblings | ||
| and children. Defaults to True. | ||
|
|
||
| Returns: | ||
| GetPartialAXTreeCommand: CDP command to get the partial AX tree. | ||
| """ | ||
| params = GetPartialAXTreeParams() | ||
| if node_id is not None: | ||
| params['nodeId'] = node_id | ||
| if backend_node_id is not None: | ||
| params['backendNodeId'] = backend_node_id | ||
| if object_id is not None: | ||
| params['objectId'] = object_id | ||
| if fetch_relatives is not None: | ||
| params['fetchRelatives'] = fetch_relatives | ||
| return Command(method=AccessibilityMethod.GET_PARTIAL_AX_TREE, params=params) | ||
|
|
||
| @staticmethod | ||
| def get_full_ax_tree( | ||
| depth: Optional[int] = None, | ||
| frame_id: Optional[str] = None, | ||
| ) -> GetFullAXTreeCommand: | ||
| """ | ||
| Fetches the entire accessibility tree for the root Document. | ||
|
|
||
| Args: | ||
| depth: The maximum depth at which descendants of the root node | ||
| should be retrieved. If omitted, the full tree is returned. | ||
| frame_id: The frame for whose document the AX tree should be | ||
| retrieved. If omitted, the root frame is used. | ||
|
|
||
| Returns: | ||
| GetFullAXTreeCommand: CDP command to get the full AX tree. | ||
| """ | ||
| params = GetFullAXTreeParams() | ||
| if depth is not None: | ||
| params['depth'] = depth | ||
| if frame_id is not None: | ||
| params['frameId'] = frame_id | ||
| return Command(method=AccessibilityMethod.GET_FULL_AX_TREE, params=params) | ||
|
|
||
| @staticmethod | ||
| def get_root_ax_node( | ||
| frame_id: Optional[str] = None, | ||
| ) -> GetRootAXNodeCommand: | ||
| """ | ||
| Fetches the root node of the accessibility tree for a Document. | ||
|
|
||
| Args: | ||
| frame_id: The frame in whose document the node resides. If omitted, | ||
| the root frame is used. | ||
|
|
||
| Returns: | ||
| GetRootAXNodeCommand: CDP command to get the root AX node. | ||
| """ | ||
| params = GetRootAXNodeParams() | ||
| if frame_id is not None: | ||
| params['frameId'] = frame_id | ||
| return Command(method=AccessibilityMethod.GET_ROOT_AX_NODE, params=params) | ||
|
|
||
| @staticmethod | ||
| def get_ax_node_and_ancestors( | ||
| node_id: Optional[int] = None, | ||
| backend_node_id: Optional[int] = None, | ||
| object_id: Optional[str] = None, | ||
| ) -> GetAXNodeAndAncestorsCommand: | ||
| """ | ||
| Fetches a node and all ancestors up to and including the root. | ||
|
|
||
| Args: | ||
| node_id: Identifier of the node to get ancestors for. | ||
| backend_node_id: Identifier of the backend node to get ancestors for. | ||
| object_id: JavaScript object id of the node wrapper to get | ||
| ancestors for. | ||
|
|
||
| Returns: | ||
| GetAXNodeAndAncestorsCommand: CDP command to get a node and its ancestors. | ||
| """ | ||
| params = GetAXNodeAndAncestorsParams() | ||
| if node_id is not None: | ||
| params['nodeId'] = node_id | ||
| if backend_node_id is not None: | ||
| params['backendNodeId'] = backend_node_id | ||
| if object_id is not None: | ||
| params['objectId'] = object_id | ||
| return Command( | ||
| method=AccessibilityMethod.GET_AX_NODE_AND_ANCESTORS, params=params | ||
| ) | ||
|
|
||
| @staticmethod | ||
| def get_child_ax_nodes( | ||
| id: AXNodeId, | ||
| frame_id: Optional[str] = None, | ||
| ) -> GetChildAXNodesCommand: | ||
| """ | ||
| Fetches a particular accessibility node by AXNodeId. | ||
|
|
||
| Args: | ||
| id: The AXNodeId of the node whose children should be retrieved. | ||
| frame_id: The frame in whose document the node resides. If omitted, | ||
| the root frame is used. | ||
|
|
||
| Returns: | ||
| GetChildAXNodesCommand: CDP command to get child AX nodes. | ||
| """ | ||
| params = GetChildAXNodesParams(id=id) | ||
| if frame_id is not None: | ||
| params['frameId'] = frame_id | ||
| return Command(method=AccessibilityMethod.GET_CHILD_AX_NODES, params=params) | ||
|
|
||
| @staticmethod | ||
| def query_ax_tree( | ||
| node_id: Optional[int] = None, | ||
| backend_node_id: Optional[int] = None, | ||
| object_id: Optional[str] = None, | ||
| accessible_name: Optional[str] = None, | ||
| role: Optional[str] = None, | ||
| ) -> QueryAXTreeCommand: | ||
| """ | ||
| Queries the accessibility tree for a DOM subtree for nodes with a | ||
| given name and/or role. | ||
|
|
||
| Args: | ||
| node_id: Identifier of the node for the root of the subtree to | ||
| search in. | ||
| backend_node_id: Identifier of the backend node for the root of | ||
| the subtree to search in. | ||
| object_id: JavaScript object id of the node wrapper for the root | ||
| of the subtree to search in. | ||
| accessible_name: Find nodes with this computed name. | ||
| role: Find nodes with this computed role. | ||
|
|
||
| Returns: | ||
| QueryAXTreeCommand: CDP command to query the AX tree. | ||
| """ | ||
| params = QueryAXTreeParams() | ||
| if node_id is not None: | ||
| params['nodeId'] = node_id | ||
| if backend_node_id is not None: | ||
| params['backendNodeId'] = backend_node_id | ||
| if object_id is not None: | ||
| params['objectId'] = object_id | ||
| if accessible_name is not None: | ||
| params['accessibleName'] = accessible_name | ||
| if role is not None: | ||
| params['role'] = role | ||
| return Command(method=AccessibilityMethod.QUERY_AX_TREE, params=params) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Accessibility domain implementation.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| from enum import Enum | ||
|
|
||
| from typing_extensions import TypedDict | ||
|
|
||
| from pydoll.protocol.accessibility.types import AXNode | ||
| from pydoll.protocol.base import CDPEvent | ||
|
|
||
|
|
||
| class AccessibilityEvent(str, Enum): | ||
| """ | ||
| Events from the Accessibility domain of the Chrome DevTools Protocol. | ||
|
|
||
| See https://chromedevtools.github.io/devtools-protocol/tot/Accessibility/ | ||
| """ | ||
|
|
||
| LOAD_COMPLETE = 'Accessibility.loadComplete' | ||
| """ | ||
| Mirrors the load complete event sent by the browser to assistive technology | ||
| when the web page has finished loading. | ||
|
|
||
| Args: | ||
| root (AXNode): New document root node. | ||
| """ | ||
|
|
||
| NODES_UPDATED = 'Accessibility.nodesUpdated' | ||
| """ | ||
| Fired when a node is updated in the accessibility tree. | ||
|
|
||
| Args: | ||
| nodes (list[AXNode]): Updated nodes. | ||
| """ | ||
|
|
||
|
|
||
| class LoadCompleteEventParams(TypedDict): | ||
| """Parameters for the loadComplete event.""" | ||
|
|
||
| root: AXNode | ||
|
|
||
|
|
||
| class NodesUpdatedEventParams(TypedDict): | ||
| """Parameters for the nodesUpdated event.""" | ||
|
|
||
| nodes: list[AXNode] | ||
|
|
||
|
|
||
| LoadCompleteEvent = CDPEvent[LoadCompleteEventParams] | ||
| NodesUpdatedEvent = CDPEvent[NodesUpdatedEventParams] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.