Class: Puppeteer::AriaQueryHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/puppeteer/aria_query_handler.rb

Instance Method Summary collapse

Instance Method Details

#query_all(element, selector) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/puppeteer/aria_query_handler.rb', line 53

def query_all(element, selector)
  context = element.execution_context
  parse_result = parse_aria_selector(selector)
  res = element.query_ax_tree(accessible_name: parse_result[:name], role: parse_result[:role])
  if res.empty?
    nil
  else
    promises = res.map do |ax_node|
      context.send(:async_adopt_backend_node_id, ax_node['backendDOMNodeId'])
    end
    await_all(*promises)
  end
end

#query_all_array(element, selector) ⇒ Object



67
68
69
70
# File 'lib/puppeteer/aria_query_handler.rb', line 67

def query_all_array(element, selector)
  element_handles = query_all(element, selector)
  element.execution_context.evaluate_handle('(...elements) => elements', *element_handles)
end

#query_one(element, selector) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/puppeteer/aria_query_handler.rb', line 28

def query_one(element, selector)
  context = element.execution_context
  parse_result = parse_aria_selector(selector)
  res = element.query_ax_tree(accessible_name: parse_result[:name], role: parse_result[:role])
  if res.empty?
    nil
  else
    context.adopt_backend_node_id(res.first['backendDOMNodeId'])
  end
end

#wait_for(dom_world, selector, visible: nil, hidden: nil, timeout: nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/puppeteer/aria_query_handler.rb', line 39

def wait_for(dom_world, selector, visible: nil, hidden: nil, timeout: nil)
  binding_function = Puppeteer::DOMWorld::BindingFunction.new(
    name: 'ariaQuerySelector',
    proc: -> (selector) { query_one(dom_world.send(:document), selector) },
  )
  dom_world.send(:wait_for_selector_in_page,
    '(_, selector) => globalThis.ariaQuerySelector(selector)',
    selector,
    visible: visible,
    hidden: hidden,
    timeout: timeout,
    binding_function: binding_function)
end