selenium.webdriver.remote.accessibility_snapshot#
Accessibility snapshots computed in the page (ADR 18205).
The tree is computed by the accessibility-snapshot atom of @selenium/atoms.
In a BiDi session it runs in a sandbox realm so page scripts cannot interfere
with it; in a WebDriver Classic session it runs through Execute Script and child
frames are reached by switching into them and back. The atom’s wire entry hands the tree back as one
JSON string beside the element and frame references, so this module holds only
what is the binding’s: the public node type and its text form, the mapping of
references to WebElement, and frame stitching.
The output is computed from the DOM following WAI-ARIA, html-aam and accname; it is not the browser’s own accessibility tree and can differ from it at the edges.
Module Attributes
|
Functions
|
Build the node tree from the atom's wire form. |
Classes
|
One node of an accessibility snapshot. |
|
Takes snapshots for one driver: runs the atom in each document and stitches child frames into the tree. |
- StateValue = bool | int | str#
True/False, a level, or"mixed".- Type:
A value in
AccessibilityNode.states
- class AccessibilityNode(role, name, description='', value=None, url=None, states=<factory>, element=None, children=<factory>)[source]#
Bases:
objectOne node of an accessibility snapshot.
- Parameters:
role (str)
name (str)
description (str)
value (str | None)
url (str | None)
states (dict[str, StateValue])
element (WebElement | None)
children (list[AccessibilityNode])
- role#
The WAI-ARIA role token;
"text"for text leaves and"iframe"for frames, under which the frame’s own tree is attached.- Type:
str
- name#
The computed accessible name,
""when there is none.- Type:
str
- description#
The computed accessible description,
""when there is none.- Type:
str
- value#
The current value for textbox, searchbox, combobox and range roles;
Nonewhere the role has none. A password field’s value is masked.- Type:
str | None
- url#
The resolved
hrefof alinkwhose element has one;Nonefor every other node. Not rendered in the text form.- Type:
str | None
- states#
checked,pressed,expanded,selected,level,disabledandfocused, each present only when it applies; new keys may be added in any release, so ignore keys you do not recognise.- Type:
dict[str, StateValue]
- element#
The element the node is backed by, usable for further commands, or
Nonefor text leaves. An element inside a child frame can be used through classic commands only once the driver has switched to that frame.- Type:
WebElement | None
- children#
The child nodes,
[]for leaves.- Type:
list[AccessibilityNode]
- role: str#
- name: str#
- description: str = ''#
- value: str | None = None#
- url: str | None = None#
- states: dict[str, StateValue]#
- element: WebElement | None = None#
- children: list[AccessibilityNode]#
- to_text()[source]#
Render the tree as text, one node per line.
The line grammar is
- role "name" [state] [state=value]: value, children indented two spaces, text leaves written as- text: content. An empty name is left out, as is an absent or empty value; aTruestate is written bare, aFalseone left out, any other value spelled. A line break or backslash in a value is escaped so a node never spans two lines. The description and element references are not rendered.- Returns:
The text form, without a trailing newline.
- Return type:
str
- node_from_wire(data, elements, frame_children)[source]#
Build the node tree from the atom’s wire form.
- Parameters:
data (dict[str, Any]) – The parsed JSON of the tree: the node’s fields, with
elementan index intoelementsand, on a frame node,framean index the binding resolves to the frame’s own tree.elements (list[WebElement]) – The elements the tree references, in the atom’s order.
frame_children (Callable[[int], list[AccessibilityNode]]) – The children of a frame node, from its
frameindex: the frame’s document, or nothing when it cannot be reached.
- Returns:
The node, with its subtree.
- Return type:
- class AccessibilitySnapshotter(driver)[source]#
Bases:
objectTakes snapshots for one driver: runs the atom in each document and stitches child frames into the tree.
- Parameters:
driver (WebDriver)
- snapshot(root, interesting_only=True)[source]#
Snapshot the driver’s current browsing context, or the subtree under
root.- Parameters:
root (WebElement | None) – The element whose subtree to snapshot, or
Nonefor the document of the driver’s current browsing context: the top-level document, or the frame the driver has switched into.interesting_only (bool) – With
Trueunnamed generic and presentational elements produce no node and their children take their place; withFalseevery rendered element produces a node.
- Returns:
The snapshot, with every reachable child frame’s tree attached under its
iframenode. The driver’s current browsing context is left as it was.- Raises:
StaleElementReferenceException – When
rootno longer belongs to a document.- Return type: