Class: Puppeteer::Frame
- Inherits:
-
Object
- Object
- Puppeteer::Frame
- Defined in:
- lib/puppeteer/frame.rb
Instance Attribute Summary collapse
-
#frame_manager ⇒ Object
Returns the value of attribute frame_manager.
-
#id ⇒ Object
Returns the value of attribute id.
-
#lifecycle_events ⇒ Object
Returns the value of attribute lifecycle_events.
-
#loader_id ⇒ Object
Returns the value of attribute loader_id.
-
#main_world ⇒ Object
Returns the value of attribute main_world.
-
#secondary_world ⇒ Object
Returns the value of attribute secondary_world.
Instance Method Summary collapse
- #add_script_tag(script_tag) ⇒ !Promise<!ElementHandle>
- #add_style_tag(style_tag) ⇒ !Promise<!ElementHandle>
- #async_click ⇒ Future
- #async_wait_for_navigation ⇒ Future
- #child_frames ⇒ Object
- #click(selector, delay: nil, button: nil, click_count: nil) ⇒ Object
- #content ⇒ Object
- #detach ⇒ Object
- #detached? ⇒ Boolean
- #evaluate(page_function, *args) ⇒ Object
- #evaluate_handle(page_function, *args) ⇒ !Promise<!Puppeteer.JSHandle>
- #execution_context ⇒ Object
- #focus(selector) ⇒ Object
- #goto(url, referer: nil, timeout: nil, wait_until: nil) ⇒ Puppeteer::Response
- #handle_lifecycle_event(loader_id, name) ⇒ Object
- #handle_loading_stopped ⇒ Object
- #hover(selector) ⇒ Object
-
#initialize(frame_manager, client, parent_frame, frame_id) ⇒ Frame
constructor
A new instance of Frame.
- #name ⇒ String
- #navigated(frame_payload) ⇒ Object
- #navigated_within_document(url) ⇒ Object
- #parent_frame ⇒ Frame?
-
#S(selector) ⇒ !Promise<?Puppeteer.ElementHandle>
‘$()` in JavaScript.
- #select(selector, *values) ⇒ !Promise<!Array<string>>
- #set_content(html, timeout: nil, wait_until: nil) ⇒ Object
-
#Seval(selector, page_function, *args) ⇒ !Promise<(!Object|undefined)>
‘$eval()` in JavaScript.
-
#SS(selector) ⇒ !Promise<!Array<!Puppeteer.ElementHandle>>
‘$$()` in JavaScript.
-
#SSeval(selector, page_function, *args) ⇒ !Promise<(!Object|undefined)>
‘$$eval()` in JavaScript.
-
#Sx(expression) ⇒ !Promise<!Array<!Puppeteer.ElementHandle>>
‘$x()` in JavaScript.
- #tap(selector) ⇒ Object
- #title ⇒ Object
- #type_text(selector, text, delay: nil) ⇒ Object
- #url ⇒ String
- #wait_for_function(page_function, options = {}, *args) ⇒ !Promise<!Puppeteer.JSHandle>
- #wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil) ⇒ Object
- #wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil) ⇒ Object
Constructor Details
#initialize(frame_manager, client, parent_frame, frame_id) ⇒ Frame
Returns a new instance of Frame.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/puppeteer/frame.rb', line 8 def initialize(frame_manager, client, parent_frame, frame_id) @frame_manager = frame_manager @client = client @parent_frame = parent_frame @id = frame_id @detached = false @loader_id = '' @lifecycle_events = Set.new @main_world = Puppeteer::DOMWorld.new(frame_manager, self, frame_manager.timeout_settings) @secondary_world = Puppeteer::DOMWorld.new(frame_manager, self, frame_manager.timeout_settings) @child_frames = Set.new if parent_frame parent_frame._child_frames << self end end |
Instance Attribute Details
#frame_manager ⇒ Object
Returns the value of attribute frame_manager.
25 26 27 |
# File 'lib/puppeteer/frame.rb', line 25 def frame_manager @frame_manager end |
#id ⇒ Object
Returns the value of attribute id.
25 26 27 |
# File 'lib/puppeteer/frame.rb', line 25 def id @id end |
#lifecycle_events ⇒ Object
Returns the value of attribute lifecycle_events.
25 26 27 |
# File 'lib/puppeteer/frame.rb', line 25 def lifecycle_events @lifecycle_events end |
#loader_id ⇒ Object
Returns the value of attribute loader_id.
25 26 27 |
# File 'lib/puppeteer/frame.rb', line 25 def loader_id @loader_id end |
#main_world ⇒ Object
Returns the value of attribute main_world.
25 26 27 |
# File 'lib/puppeteer/frame.rb', line 25 def main_world @main_world end |
#secondary_world ⇒ Object
Returns the value of attribute secondary_world.
25 26 27 |
# File 'lib/puppeteer/frame.rb', line 25 def secondary_world @secondary_world end |
Instance Method Details
#add_script_tag(script_tag) ⇒ !Promise<!ElementHandle>
145 146 147 |
# File 'lib/puppeteer/frame.rb', line 145 def add_script_tag(script_tag) @main_world.add_script_tag(script_tag) end |
#add_style_tag(style_tag) ⇒ !Promise<!ElementHandle>
151 152 153 |
# File 'lib/puppeteer/frame.rb', line 151 def add_style_tag(style_tag) @main_world.add_style_tag(style_tag) end |
#async_click ⇒ Future
160 161 162 |
# File 'lib/puppeteer/frame.rb', line 160 async def async_click(selector, delay: nil, button: nil, click_count: nil) click(selector, delay: delay, button: , click_count: click_count) end |
#async_wait_for_navigation ⇒ Future
45 46 47 |
# File 'lib/puppeteer/frame.rb', line 45 async def (timeout: nil, wait_until: nil) (timeout: timeout, wait_until: wait_until) end |
#child_frames ⇒ Object
135 136 137 |
# File 'lib/puppeteer/frame.rb', line 135 def child_frames @child_frames.dup end |
#click(selector, delay: nil, button: nil, click_count: nil) ⇒ Object
168 169 170 |
# File 'lib/puppeteer/frame.rb', line 168 def click(selector, delay: nil, button: nil, click_count: nil) @secondary_world.click(selector, delay: delay, button: , click_count: click_count) end |
#content ⇒ Object
106 107 108 |
# File 'lib/puppeteer/frame.rb', line 106 def content @secondary_world.content end |
#detach ⇒ Object
295 296 297 298 299 300 301 302 303 |
# File 'lib/puppeteer/frame.rb', line 295 def detach @detached = true @main_world.detach @secondary_world.detach if @parent_frame @parent_frame._child_frames.delete(self) end @parent_frame = nil end |
#detached? ⇒ Boolean
139 140 141 |
# File 'lib/puppeteer/frame.rb', line 139 def detached? @detached end |
#evaluate(page_function, *args) ⇒ Object
61 62 63 |
# File 'lib/puppeteer/frame.rb', line 61 def evaluate(page_function, *args) @main_world.evaluate(page_function, *args) end |
#evaluate_handle(page_function, *args) ⇒ !Promise<!Puppeteer.JSHandle>
55 56 57 |
# File 'lib/puppeteer/frame.rb', line 55 def evaluate_handle(page_function, *args) @main_world.evaluate_handle(page_function, *args) end |
#execution_context ⇒ Object
49 50 51 |
# File 'lib/puppeteer/frame.rb', line 49 def execution_context @main_world.execution_context end |
#focus(selector) ⇒ Object
173 174 175 |
# File 'lib/puppeteer/frame.rb', line 173 def focus(selector) @secondary_world.focus(selector) end |
#goto(url, referer: nil, timeout: nil, wait_until: nil) ⇒ Puppeteer::Response
32 33 34 |
# File 'lib/puppeteer/frame.rb', line 32 def goto(url, referer: nil, timeout: nil, wait_until: nil) @frame_manager.navigate_frame(self, url, referer: referer, timeout: timeout, wait_until: wait_until) end |
#handle_lifecycle_event(loader_id, name) ⇒ Object
282 283 284 285 286 287 288 |
# File 'lib/puppeteer/frame.rb', line 282 def handle_lifecycle_event(loader_id, name) if name == 'init' @loader_id = loader_id @lifecycle_events.clear end @lifecycle_events << name end |
#handle_loading_stopped ⇒ Object
290 291 292 293 |
# File 'lib/puppeteer/frame.rb', line 290 def handle_loading_stopped @lifecycle_events << 'DOMContentLoaded' @lifecycle_events << 'load' end |
#hover(selector) ⇒ Object
178 179 180 |
# File 'lib/puppeteer/frame.rb', line 178 def hover(selector) @secondary_world.hover(selector) end |
#name ⇒ String
117 118 119 |
# File 'lib/puppeteer/frame.rb', line 117 def name @name || '' end |
#navigated(frame_payload) ⇒ Object
266 267 268 269 270 271 272 273 274 275 |
# File 'lib/puppeteer/frame.rb', line 266 def navigated(frame_payload) @name = frame_payload['name'] # TODO(lushnikov): remove this once requestInterception has loaderId exposed. = frame_payload['url'] @url = frame_payload['url'] # Ensure loaderId updated. # The order of [Page.lifecycleEvent name="init"] and [Page.frameNavigated] is random... for some reason... @loader_id = frame_payload['loaderId'] end |
#navigated_within_document(url) ⇒ Object
278 279 280 |
# File 'lib/puppeteer/frame.rb', line 278 def navigated_within_document(url) @url = url end |
#parent_frame ⇒ Frame?
127 128 129 |
# File 'lib/puppeteer/frame.rb', line 127 def parent_frame @parent_frame end |
#S(selector) ⇒ !Promise<?Puppeteer.ElementHandle>
‘$()` in JavaScript. $ is not allowed to use as a method name in Ruby.
68 69 70 |
# File 'lib/puppeteer/frame.rb', line 68 def S(selector) @main_world.S(selector) end |
#select(selector, *values) ⇒ !Promise<!Array<string>>
185 186 187 |
# File 'lib/puppeteer/frame.rb', line 185 def select(selector, *values) @secondary_world.select(selector, *values) end |
#set_content(html, timeout: nil, wait_until: nil) ⇒ Object
112 113 114 |
# File 'lib/puppeteer/frame.rb', line 112 def set_content(html, timeout: nil, wait_until: nil) @secondary_world.set_content(html, timeout: timeout, wait_until: wait_until) end |
#Seval(selector, page_function, *args) ⇒ !Promise<(!Object|undefined)>
‘$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.
86 87 88 |
# File 'lib/puppeteer/frame.rb', line 86 def Seval(selector, page_function, *args) @main_world.Seval(selector, page_function, *args) end |
#SS(selector) ⇒ !Promise<!Array<!Puppeteer.ElementHandle>>
‘$$()` in JavaScript. $ is not allowed to use as a method name in Ruby.
102 103 104 |
# File 'lib/puppeteer/frame.rb', line 102 def SS(selector) @main_world.SS(selector) end |
#SSeval(selector, page_function, *args) ⇒ !Promise<(!Object|undefined)>
‘$$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.
95 96 97 |
# File 'lib/puppeteer/frame.rb', line 95 def SSeval(selector, page_function, *args) @main_world.SSeval(selector, page_function, *args) end |
#Sx(expression) ⇒ !Promise<!Array<!Puppeteer.ElementHandle>>
‘$x()` in JavaScript. $ is not allowed to use as a method name in Ruby.
76 77 78 |
# File 'lib/puppeteer/frame.rb', line 76 def Sx(expression) @main_world.Sx(expression) end |
#tap(selector) ⇒ Object
190 191 192 |
# File 'lib/puppeteer/frame.rb', line 190 def tap(selector) @secondary_world.tap(selector) end |
#title ⇒ Object
261 262 263 |
# File 'lib/puppeteer/frame.rb', line 261 def title @secondary_world.title end |
#type_text(selector, text, delay: nil) ⇒ Object
197 198 199 |
# File 'lib/puppeteer/frame.rb', line 197 def type_text(selector, text, delay: nil) @main_world.type_text(selector, text, delay: delay) end |
#url ⇒ String
122 123 124 |
# File 'lib/puppeteer/frame.rb', line 122 def url @url end |
#wait_for_function(page_function, options = {}, *args) ⇒ !Promise<!Puppeteer.JSHandle>
257 258 259 |
# File 'lib/puppeteer/frame.rb', line 257 def wait_for_function(page_function, = {}, *args) @main_world.wait_for_function(page_function, , *args) end |
#wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil) ⇒ Object
227 228 229 230 231 232 233 234 235 236 |
# File 'lib/puppeteer/frame.rb', line 227 def wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil) handle = @secondary_world.wait_for_selector(selector, visible: visible, hidden: hidden, timeout: timeout) if !handle return nil end main_execution_context = @main_world.execution_context result = main_execution_context.adopt_element_handle(handle) handle.dispose result end |
#wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil) ⇒ Object
242 243 244 245 246 247 248 249 250 251 |
# File 'lib/puppeteer/frame.rb', line 242 def wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil) handle = @secondary_world.wait_for_xpath(xpath, visible: visible, hidden: hidden, timeout: timeout) if !handle return nil end main_execution_context = @main_world.execution_context result = main_execution_context.adopt_element_handle(handle) handle.dispose result end |