Class: Playwright::Accessibility

Inherits:
PlaywrightApi show all
Defined in:
lib/playwright_api/accessibility.rb

Overview

The Accessibility class provides methods for inspecting Chromium’s accessibility tree. The accessibility tree is used by assistive technology such as [screen readers](en.wikipedia.org/wiki/Screen_reader) or [switches](en.wikipedia.org/wiki/Switch_access).

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.

Instance Method Summary collapse

Methods inherited from PlaywrightApi

#initialize, unwrap, wrap

Constructor Details

This class inherits a constructor from Playwright::PlaywrightApi

Instance Method Details

#snapshot(interestingOnly: nil, root: nil) ⇒ Object

Deprecated.

This method is deprecated. Please use other libraries such as [Axe](www.deque.com/axe/) if you need to test page accessibility. See our Node.js [guide](playwright.dev/docs/accessibility-testing) for integration with Axe.

Captures the current state of the accessibility tree. The returned object represents the root accessible node of the page.

NOTE: 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 ‘interestingOnly` is set to `false`.

Usage

An example of dumping the entire accessibility tree:

“‘python sync snapshot = page.accessibility.snapshot() print(snapshot) “`

An example of logging the focused node’s name:

“‘python sync 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"])

“‘



53
54
55
# File 'lib/playwright_api/accessibility.rb', line 53

def snapshot(interestingOnly: nil, root: nil)
  wrap_impl(@impl.snapshot(interestingOnly: unwrap_impl(interestingOnly), root: unwrap_impl(root)))
end