Accessibility is a very platform-specific thing. On different platforms, there are different screen readers that might have wildly different output.

    Most of the accessibility tree gets filtered out when converting from Blink 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.

    accessibility.snapshot([options])

    • <>
      • interestingOnly <boolean> Prune uninteresting nodes from the tree. Defaults to true.
      • root <> The root DOM element for the snapshot. Defaults to the whole page.
    • returns: <Promise<?>> An AXNode object with the following properties:
      • role <> The role.
      • name <> A human readable name for the node.
      • value <string|> The current value of the node, if applicable.
      • description <string> An additional human readable description of the node, if applicable.
      • keyshortcuts <> Keyboard shortcuts associated with this node, if applicable.
      • roledescription <string> A human readable alternative to the role, if applicable.
      • valuetext <> A description of the current value, if applicable.
      • disabled <boolean> Whether the node is disabled, if applicable.
      • focused <> Whether the node is focused, if applicable.
      • modal <boolean> Whether the node is , if applicable.
      • <boolean> Whether the node text input supports multiline, if applicable.
      • multiselectable <> Whether more than one child can be selected, if applicable.
      • readonly <boolean> Whether the node is read only, if applicable.
      • required <> Whether the node is required, if applicable.
      • selected <boolean> Whether the node is selected in its parent node, if applicable.
      • checked <|”mixed”> Whether the checkbox is checked, or “mixed”, if applicable.
      • pressed <boolean|”mixed”> Whether the toggle button is checked, or “mixed”, if applicable.
      • level <> The level of a heading, if applicable.
      • valuemin <number> The minimum value in a node, if applicable.
      • valuemax <> The maximum value in a node, if applicable.
      • autocomplete <string> What kind of autocomplete is supported by a control, if applicable.
      • haspopup <> What kind of popup is currently being shown for a node, if applicable.
      • orientation <string> Whether the node is oriented horizontally or vertically, if applicable.
      • children <<Object>> Child s of this node, if any, if applicable.

    An example of logging the focused node’s name:

    1. const snapshot = await page.accessibility.snapshot();
    2. const node = findFocusedNode(snapshot);
    3. console.log(node && node.name);
    4. function findFocusedNode(node) {
    5. if (node.focused)
    6. return node;
    7. for (const child of node.children || []) {
    8. const foundNode = findFocusedNode(child);
    9. return foundNode;
    10. }
    11. return null;