Class: Ferrum::Accessibility
- Inherits:
-
Object
- Object
- Ferrum::Accessibility
- Defined in:
- lib/ferrum/accessibility.rb,
lib/ferrum/accessibility/ax_node.rb
Overview
The node-scoped methods (node_for, partial_tree, query with a
node:) issue the command against the node's owning page session. They
support same-process (same-target) iframes; nodes living in an
out-of-process iframe (OOPIF, separate CDP target) are not resolvable and
will error or return an empty result.
Wraps the CDP Accessibility
domain. The query commands work without enable; enable/disable are
provided for completeness (live AX events).
Defined Under Namespace
Classes: AXNode
Instance Method Summary collapse
-
#disable ⇒ self
Disables the Accessibility domain.
-
#enable ⇒ self
Enables the Accessibility domain, activating live AX tree change events.
-
#initialize(page) ⇒ Accessibility
constructor
A new instance of Accessibility.
-
#node_for(node) ⇒ AXNode?
The single non-ignored AXNode for a DOM node, or
nil. -
#partial_tree(node:, fetch_relatives: false) ⇒ Array<AXNode>
The partial AX tree for a DOM node.
-
#query(name: nil, role: nil, node: nil) ⇒ Array<AXNode>
Query the AX tree by accessible name and/or role.
-
#root(frame_id: nil) ⇒ AXNode?
The root AXNode of the (optionally framed) document.
-
#snapshot(depth: nil, frame_id: nil) ⇒ Array<AXNode>
The full AX tree for the page.
Constructor Details
#initialize(page) ⇒ Accessibility
Returns a new instance of Accessibility.
18 19 20 |
# File 'lib/ferrum/accessibility.rb', line 18 def initialize(page) @page = page end |
Instance Method Details
#disable ⇒ self
Disables the Accessibility domain.
95 96 97 98 |
# File 'lib/ferrum/accessibility.rb', line 95 def disable @page.command("Accessibility.disable") self end |
#enable ⇒ self
Enables the Accessibility domain, activating live AX tree change events.
87 88 89 90 |
# File 'lib/ferrum/accessibility.rb', line 87 def enable @page.command("Accessibility.enable") self end |
#node_for(node) ⇒ AXNode?
The single non-ignored AXNode for a DOM node, or nil.
28 29 30 |
# File 'lib/ferrum/accessibility.rb', line 28 def node_for(node) partial_tree(node: node).find { |ax_node| !ax_node.ignored? } end |
#partial_tree(node:, fetch_relatives: false) ⇒ Array<AXNode>
The partial AX tree for a DOM node.
39 40 41 42 43 44 |
# File 'lib/ferrum/accessibility.rb', line 39 def partial_tree(node:, fetch_relatives: false) nodes = node.page.command("Accessibility.getPartialAXTree", nodeId: node.node_id, fetchRelatives: fetch_relatives)["nodes"] build(nodes) end |
#query(name: nil, role: nil, node: nil) ⇒ Array<AXNode>
Query the AX tree by accessible name and/or role.
66 67 68 69 70 71 |
# File 'lib/ferrum/accessibility.rb', line 66 def query(name: nil, role: nil, node: nil) page = node ? node.page : @page params = { accessibleName: name, role: role }.compact params[:nodeId] = node ? node.node_id : page.document_node_id build(page.command("Accessibility.queryAXTree", **params)["nodes"]) end |
#root(frame_id: nil) ⇒ AXNode?
The root AXNode of the (optionally framed) document.
79 80 81 82 |
# File 'lib/ferrum/accessibility.rb', line 79 def root(frame_id: nil) params = { depth: 1, frameId: frame_id }.compact build(@page.command("Accessibility.getFullAXTree", **params)["nodes"]).first end |
#snapshot(depth: nil, frame_id: nil) ⇒ Array<AXNode>
The full AX tree for the page.
53 54 55 56 |
# File 'lib/ferrum/accessibility.rb', line 53 def snapshot(depth: nil, frame_id: nil) params = { depth: depth, frameId: frame_id }.compact build(@page.command("Accessibility.getFullAXTree", **params)["nodes"]) end |