Module: Ferrum::Page::DOM

Included in:
Ferrum::Page
Defined in:
lib/ferrum/page/dom.rb

Instance Method Summary collapse

Instance Method Details

#at_css(selector, within: nil) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/ferrum/page/dom.rb', line 43

def at_css(selector, within: nil)
  node_id = within&.node_id || @document_id

  id = command("DOM.querySelector",
               nodeId: node_id,
               selector: selector)["nodeId"]
  build_node(id)
end

#at_xpath(selector, within: nil) ⇒ Object

Raises:



26
27
28
# File 'lib/ferrum/page/dom.rb', line 26

def at_xpath(selector, within: nil)
  raise NotImplemented
end

#bodyObject



14
15
16
# File 'lib/ferrum/page/dom.rb', line 14

def body
  evaluate("document.documentElement.outerHTML")
end

#css(selector, within: nil) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/ferrum/page/dom.rb', line 34

def css(selector, within: nil)
  node_id = within&.node_id || @document_id

  ids = command("DOM.querySelectorAll",
                nodeId: node_id,
                selector: selector)["nodeIds"]
  ids.map { |id| build_node(id) }.compact
end

#current_urlObject



6
7
8
# File 'lib/ferrum/page/dom.rb', line 6

def current_url
  evaluate("window.top.location.href")
end

#property(node, name) ⇒ Object



18
19
20
# File 'lib/ferrum/page/dom.rb', line 18

def property(node, name)
  evaluate_on(node: node, expression: %Q(this["#{name}"]))
end

#select_file(node, value) ⇒ Object



22
23
24
# File 'lib/ferrum/page/dom.rb', line 22

def select_file(node, value)
  command("DOM.setFileInputFiles", nodeId: node.node_id, files: Array(value))
end

#titleObject



10
11
12
# File 'lib/ferrum/page/dom.rb', line 10

def title
  evaluate("window.top.document.title")
end

#xpath(selector, within: nil) ⇒ Object

Raises:



30
31
32
# File 'lib/ferrum/page/dom.rb', line 30

def xpath(selector, within: nil)
  raise NotImplemented
end