Class: Selenium::WebDriver::AccessibilityNode
| Relationships & Source Files | |
| Namespace Children | |
|
Modules:
| |
| Inherits: | Object |
| Defined in: | rb/lib/selenium/webdriver/common/accessibility_snapshot.rb |
Overview
One node of an accessibility snapshot (ADR 18205), as returned by Driver#accessibility_snapshot and Element#accessibility_snapshot.
The tree is computed in the page from the DOM following WAI-ARIA, html-aam and accname. It is not the browser's own accessibility tree and can differ from it at the edges.
Constant Summary
-
STATE_ORDER =
# File 'rb/lib/selenium/webdriver/common/accessibility_snapshot.rb', line 33
The order the text form writes states in (ADR 18205 §1).
%w[checked pressed expanded selected level disabled focused].freeze
Class Method Summary
-
.from_wire(data, elements, &frame_children)
Internal use only
Builds the node tree from the atom's wire form: the parsed JSON of the tree, in which #element is an index into
elementsand, on a frame node,framean index the block resolves to the frame's own tree (its document, or nothing when it cannot be reached). - .new(role:, name:, description: '', value: nil, url: nil, states: {}, element: nil, children: []) ⇒ AccessibilityNode constructor
Instance Attribute Summary
- #children ⇒ Array<AccessibilityNode> rw
- #description ⇒ String readonly
- #element ⇒ Element? readonly
- #name ⇒ String readonly
- #role ⇒ String readonly
- #states ⇒ Hash{String => Boolean, Integer, String} readonly
- #url ⇒ String? readonly
- #value ⇒ String? readonly
Instance Method Summary
-
#to_text ⇒ String
Renders the tree as text, one node per line.
- #line private
- #one_line(text) private
- #quote(text) private
-
#state_tokens
private
A true state bare, a false one left out, any other value spelled.
Constructor Details
.new(role:, name:, description: '', value: nil, url: nil, states: {}, element: nil, children: []) ⇒ AccessibilityNode
# File 'rb/lib/selenium/webdriver/common/accessibility_snapshot.rb', line 66
def initialize(role:, name:, description: '', value: nil, url: nil, states: {}, element: nil, children: []) @role = role @name = name @description = description @value = value @url = url @states = states @element = element @children = children end
Class Method Details
.from_wire(data, elements, &frame_children)
Builds the node tree from the atom's wire form: the parsed JSON of the tree, in
which #element is an index into elements and, on a frame node, frame an index
the block resolves to the frame's own tree (its document, or nothing when it
cannot be reached).
# File 'rb/lib/selenium/webdriver/common/accessibility_snapshot.rb', line 103
def self.from_wire(data, elements, &frame_children) children = if data.key?('frame') yield data['frame'] else data.fetch('children').map { |child| from_wire(child, elements, &frame_children) } end element_index = data['element'] new( role: data.fetch('role'), name: data.fetch('name'), description: data.fetch('description', ''), value: data['value'], url: data['url'], states: data.fetch('states').dup, element: element_index && elements.fetch(element_index), children: children ) end
Instance Attribute Details
#children ⇒ Array<AccessibilityNode> (rw)
# File 'rb/lib/selenium/webdriver/common/accessibility_snapshot.rb', line 64
attr_accessor :children
#description ⇒ String (readonly)
# File 'rb/lib/selenium/webdriver/common/accessibility_snapshot.rb', line 43
attr_reader :description
#element ⇒ Element? (readonly)
# File 'rb/lib/selenium/webdriver/common/accessibility_snapshot.rb', line 61
attr_reader :element
#name ⇒ String (readonly)
# File 'rb/lib/selenium/webdriver/common/accessibility_snapshot.rb', line 40
attr_reader :name
#role ⇒ String (readonly)
# File 'rb/lib/selenium/webdriver/common/accessibility_snapshot.rb', line 37
attr_reader :role
#states ⇒ Hash{String => Boolean, Integer, String} (readonly)
# File 'rb/lib/selenium/webdriver/common/accessibility_snapshot.rb', line 56
attr_reader :states
#url ⇒ String? (readonly)
# File 'rb/lib/selenium/webdriver/common/accessibility_snapshot.rb', line 51
attr_reader :url
#value ⇒ String? (readonly)
# File 'rb/lib/selenium/webdriver/common/accessibility_snapshot.rb', line 47
attr_reader :value
Instance Method Details
#line (private)
[ GitHub ]#one_line(text) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/accessibility_snapshot.rb', line 194
def one_line(text) text.gsub('\\') { '\\\\' }.gsub("\r") { '\\r' }.gsub("\n") { '\\n' } end
#quote(text) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/accessibility_snapshot.rb', line 190
def quote(text) "\"#{text.gsub('\\') { '\\\\' }.gsub('"') { '\\"' }}\"" end
#state_tokens (private)
A true state bare, a false one left out, any other value spelled.
# File 'rb/lib/selenium/webdriver/common/accessibility_snapshot.rb', line 178
def state_tokens tokens = STATE_ORDER.filter_map do |key| next unless states.key?(key) state = states[key] next if state == false state == true ? " [#{key}]" : " [#{key}=#{state}]" end tokens.join end
#to_text ⇒ String
Renders the tree as text, one node per line.
The line grammar is - role "name" [state] [state=value]: value, children indented two spaces, text leaves written as - text: content. An empty name is left out, as is an absent or empty value; a true state is written bare, a false one left out, any other value spelled. A line break or backslash in a value is escaped so a node never spans two lines. The description and element references are not rendered.
# File 'rb/lib/selenium/webdriver/common/accessibility_snapshot.rb', line 90
def to_text lines('').join("\n") end