Accessibility
The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by assistive technology such as screen readers or switches.
Accessibility is a very platform-specific thing. On different platforms, there are different screen readers that might have wildly different output.
Rendering engines of Chromium, Firefox and WebKit have a concept of "accessibility tree", which is then translated into different platform-specific APIs. Accessibility namespace gives access to this Accessibility Tree.
Most of the accessibility tree gets filtered out when converting from internal browser AX Tree to Platform-specific AX-Tree or by assistive technologies themselves. By default, Playwright tries to approximate this filtering, exposing only the "interesting" nodes of the tree.
Deprecated
snapshot
Added before v1.9Captures the current state of the accessibility tree. The returned object represents the root accessible node of the page.
The Chromium accessibility tree contains nodes that go unused on most platforms and by most screen readers. Playwright will discard them as well for an easier to process tree, unless interesting_only is set to false.
Usage
An example of dumping the entire accessibility tree:
- Sync
- Async
snapshot = page.accessibility.snapshot()
print(snapshot)
snapshot = await page.accessibility.snapshot()
print(snapshot)
An example of logging the focused node's name:
- Sync
- Async
def find_focused_node(node):
if node.get("focused"):
return node
for child in (node.get("children") or []):
found_node = find_focused_node(child)
if found_node:
return found_node
return None
snapshot = page.accessibility.snapshot()
node = find_focused_node(snapshot)
if node:
print(node["name"])
def find_focused_node(node):
if node.get("focused"):
return node
for child in (node.get("children") or []):
found_node = find_focused_node(child)
if found_node:
return found_node
return None
snapshot = await page.accessibility.snapshot()
node = find_focused_node(snapshot)
if node:
print(node["name"])
Arguments
-
interesting_onlybool (optional)#Prune uninteresting nodes from the tree. Defaults to
true. -
rootElementHandle (optional)#The root DOM element for the snapshot. Defaults to the whole page.
Returns
- NoneType | Dict#
-
rolestrThe role.
-
namestrA human readable name for the node.
-
The current value of the node, if applicable.
-
descriptionstrAn additional human readable description of the node, if applicable.
-
keyshortcutsstrKeyboard shortcuts associated with this node, if applicable.
-
roledescriptionstrA human readable alternative to the role, if applicable.
-
valuetextstrA description of the current value, if applicable.
-
disabledboolWhether the node is disabled, if applicable.
-
expandedboolWhether the node is expanded or collapsed, if applicable.
-
focusedboolWhether the node is focused, if applicable.
-
modalboolWhether the node is modal, if applicable.
-
multilineboolWhether the node text input supports multiline, if applicable.
-
multiselectableboolWhether more than one child can be selected, if applicable.
-
readonlyboolWhether the node is read only, if applicable.
-
requiredboolWhether the node is required, if applicable.
-
selectedboolWhether the node is selected in its parent node, if applicable.
-
checkedbool | "mixed"Whether the checkbox is checked, or "mixed", if applicable.
-
pressedbool | "mixed"Whether the toggle button is checked, or "mixed", if applicable.
-
levelintThe level of a heading, if applicable.
-
valueminfloatThe minimum value in a node, if applicable.
-
valuemaxfloatThe maximum value in a node, if applicable.
-
autocompletestrWhat kind of autocomplete is supported by a control, if applicable.
-
haspopupstrWhat kind of popup is currently being shown for a node, if applicable.
-
invalidstrWhether and in what way this node's value is invalid, if applicable.
-
orientationstrWhether the node is oriented horizontally or vertically, if applicable.
-
Child nodes, if any, if applicable.
-