Module: Capybara::Lightpanda::Browser::Finder

Included in:
Capybara::Lightpanda::Browser
Defined in:
lib/capybara/lightpanda/browser/finder.rb

Overview

Element finding in the three dispatch contexts (document, node- scoped, iframe) plus the shared XPath/CSS find fragments and InvalidSelector translation.

Instance Method Summary collapse

Instance Method Details

#find(method, selector) ⇒ Object

Find elements in the current context (top frame or active frame). Returns an array of remote object ID strings.



12
13
14
15
16
17
18
# File 'lib/capybara/lightpanda/browser/finder.rb', line 12

def find(method, selector)
  if @frame_stack.empty?
    find_in_document(method, selector)
  else
    find_in_frame(method, selector)
  end
end

#find_within(remote_object_id, method, selector) ⇒ Object

Find child elements within a specific node. Returns an array of remote object ID strings.

Wrapped in with_default_context_wait so a click that triggered a navigation immediately before the find (e.g. a fill_in following a link that mutated the DOM) doesn't race against Runtime.executionContextCreated and surface as NoExecutionContextError. find_in_document and find_in_frame already use the same wrapper; find_within was the odd one out.



29
30
31
32
33
34
35
36
# File 'lib/capybara/lightpanda/browser/finder.rb', line 29

def find_within(remote_object_id, method, selector)
  with_default_context_wait do
    result = call_function_on(remote_object_id, FIND_WITHIN_JS, method, selector, return_by_value: false)
    extract_node_object_ids(result)
  end
rescue JavaScriptError => e
  raise_invalid_selector(e, method, selector)
end

#parents_of(remote_object_id) ⇒ Object

Ancestor chain of remote_object_id from parentNode up to (but excluding) document, returned as an array of remote object IDs. Mirrors Cuprite's JS parents helper. Same with_default_context_wait wrapping as find_within — same race window applies.



42
43
44
45
46
47
# File 'lib/capybara/lightpanda/browser/finder.rb', line 42

def parents_of(remote_object_id)
  with_default_context_wait do
    result = call_function_on(remote_object_id, PARENTS_JS, return_by_value: false)
    extract_node_object_ids(result)
  end
end