module Ferrum::Frame::DOM
Public Instance Methods
at_css(selector, within: nil)
click to toggle source
# File lib/ferrum/frame/dom.rb, line 79 def at_css(selector, within: nil) expr = <<~JS function(selector, within) { within ||= document return within.querySelector(selector); } JS evaluate_func(expr, selector, within) end
at_xpath(selector, within: nil)
click to toggle source
# File lib/ferrum/frame/dom.rb, line 57 def at_xpath(selector, within: nil) expr = <<~JS function(selector, within) { within ||= document let xpath = document.evaluate(selector, within, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); return xpath.snapshotItem(0); } JS evaluate_func(expr, selector, within) end
body()
click to toggle source
# File lib/ferrum/frame/dom.rb, line 35 def body evaluate("document.documentElement.outerHTML") end
css(selector, within: nil)
click to toggle source
# File lib/ferrum/frame/dom.rb, line 68 def css(selector, within: nil) expr = <<~JS function(selector, within) { within ||= document return Array.from(within.querySelectorAll(selector)); } JS evaluate_func(expr, selector, within) end
current_title()
click to toggle source
# File lib/ferrum/frame/dom.rb, line 27 def current_title evaluate("window.top.document.title") end
current_url()
click to toggle source
# File lib/ferrum/frame/dom.rb, line 23 def current_url evaluate("window.top.location.href") end
doctype()
click to toggle source
# File lib/ferrum/frame/dom.rb, line 31 def doctype evaluate("document.doctype && new XMLSerializer().serializeToString(document.doctype)") end
xpath(selector, within: nil)
click to toggle source
# File lib/ferrum/frame/dom.rb, line 39 def xpath(selector, within: nil) expr = <<~JS function(selector, within) { let results = []; within ||= document let xpath = document.evaluate(selector, within, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); for (let i = 0; i < xpath.snapshotLength; i++) { results.push(xpath.snapshotItem(i)); } return results; } JS evaluate_func(expr, selector, within) end