Method: Playwright::Accessibility#snapshot

Defined in:
lib/playwright_api/accessibility.rb

#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`.

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"])

“‘



55
56
57
# File 'lib/playwright_api/accessibility.rb', line 55

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