Class: Ferrum::Frame

Inherits:
Object
  • Object
show all
Includes:
DOM, Runtime
Defined in:
lib/ferrum/frame.rb,
lib/ferrum/frame/dom.rb,
lib/ferrum/frame/runtime.rb

Defined Under Namespace

Modules: DOM, Runtime

Constant Summary

Constants included from Runtime

Runtime::INTERMITTENT_ATTEMPTS, Runtime::INTERMITTENT_SLEEP, Runtime::LINK_TAG, Runtime::SCRIPT_SRC_TAG, Runtime::SCRIPT_TEXT_TAG, Runtime::STYLE_TAG

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DOM

#at_css, #at_xpath, #body, #css, #current_title, #current_url, #doctype, #xpath

Methods included from Runtime

#add_script_tag, #add_style_tag, #evaluate, #evaluate_async, #evaluate_func, #evaluate_on, #execute

Constructor Details

#initialize(id, page, parent_id = nil) ⇒ Frame

Returns a new instance of Frame.



13
14
15
16
# File 'lib/ferrum/frame.rb', line 13

def initialize(id, page, parent_id = nil)
  @execution_id = nil
  @id, @page, @parent_id = id, page, parent_id
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



11
12
13
# File 'lib/ferrum/frame.rb', line 11

def id
  @id
end

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/ferrum/frame.rb', line 11

def name
  @name
end

#pageObject (readonly)

Returns the value of attribute page.



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

def page
  @page
end

#parent_idObject (readonly)

Returns the value of attribute parent_id.



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

def parent_id
  @parent_id
end

#stateObject

Returns the value of attribute state.



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

def state
  @state
end

Instance Method Details

#execution_idObject



51
52
53
54
55
56
57
# File 'lib/ferrum/frame.rb', line 51

def execution_id
  raise NoExecutionContextError unless @execution_id
  @execution_id
rescue NoExecutionContextError
  @page.event.reset
  @page.event.wait(@page.timeout) ? retry : raise
end

#execution_id?(execution_id) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/ferrum/frame.rb', line 47

def execution_id?(execution_id)
  @execution_id == execution_id
end

#inspectObject



67
68
69
# File 'lib/ferrum/frame.rb', line 67

def inspect
  %(#<#{self.class} @id=#{@id.inspect} @parent_id=#{@parent_id.inspect} @name=#{@name.inspect} @state=#{@state.inspect} @execution_id=#{@execution_id.inspect}>)
end

#main?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/ferrum/frame.rb', line 34

def main?
  @parent_id.nil?
end

#reset_execution_idObject



63
64
65
# File 'lib/ferrum/frame.rb', line 63

def reset_execution_id
  @execution_id = nil
end

#set_content(html) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/ferrum/frame.rb', line 38

def set_content(html)
  evaluate_async(%(
    document.open();
    document.write(arguments[0]);
    document.close();
    arguments[1](true);
  ), @page.timeout, html)
end

#set_execution_id(value) ⇒ Object



59
60
61
# File 'lib/ferrum/frame.rb', line 59

def set_execution_id(value)
  @execution_id ||= value
end

#titleObject



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

def title
  evaluate("document.title")
end

#urlObject



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

def url
  evaluate("document.location.href")
end