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::DEFAULT_OPTIONS, Runtime::EVALUATE_ASYNC_OPTIONS, Runtime::EXECUTE_OPTIONS, 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_on, #execute

Constructor Details

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

Returns a new instance of Frame.



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

def initialize(id, page, parent_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



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

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)


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

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

#inspectObject



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

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)


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

def main?
  @parent_id.nil?
end

#reset_execution_idObject



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

def reset_execution_id
  @execution_id = nil
end

#set_content(html) ⇒ Object



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

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



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

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

#titleObject



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

def title
  evaluate("document.title")
end

#urlObject



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

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