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.
-
#puppeteer_world ⇒ Object
Returns the value of attribute puppeteer_world.
Instance Method Summary collapse
- #_client ⇒ Object
- #add_script_tag(url: nil, path: nil, content: nil, type: nil, id: nil) ⇒ Object
- #add_style_tag(url: nil, path: nil, content: nil) ⇒ Object
- #child_frames ⇒ Object
- #click(selector, delay: nil, button: nil, click_count: nil) ⇒ Object
- #content ⇒ String
- #detach ⇒ Object
- #detached? ⇒ Boolean
-
#eval_on_selector(selector, page_function, *args) ⇒ !Promise<(!Object|undefined)>
(also: #Seval)
‘$eval()` in JavaScript.
-
#eval_on_selector_all(selector, page_function, *args) ⇒ !Promise<(!Object|undefined)>
(also: #SSeval)
‘$$eval()` in JavaScript.
- #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::HTTPResponse
- #handle_lifecycle_event(loader_id, name) ⇒ Object
- #handle_loading_started ⇒ Object
- #handle_loading_stopped ⇒ Object
- #has_started_loading? ⇒ Boolean
- #hover(selector) ⇒ Object
-
#initialize(frame_manager, parent_frame, frame_id, client) ⇒ Frame
constructor
A new instance of Frame.
- #inspect ⇒ Object
- #name ⇒ String
- #navigated(frame_payload) ⇒ Object
- #navigated_within_document(url) ⇒ Object
- #oop_frame? ⇒ Boolean
- #page ⇒ Object
- #parent_frame ⇒ Frame?
-
#query_selector(selector) ⇒ !Promise<?Puppeteer.ElementHandle>
(also: #S)
‘$()` in JavaScript.
-
#query_selector_all(selector) ⇒ !Promise<!Array<!Puppeteer.ElementHandle>>
(also: #SS)
‘$$()` in JavaScript.
- #select(selector, *values) ⇒ !Promise<!Array<string>>
- #set_content(html, timeout: nil, wait_until: nil) ⇒ Object
-
#Sx(expression) ⇒ !Promise<!Array<!Puppeteer.ElementHandle>>
‘$x()` in JavaScript.
- #tap(selector) ⇒ Object
- #title ⇒ String
- #type_text(selector, text, delay: nil) ⇒ Object
- #url ⇒ String
- #wait_for_function(page_function, args: [], polling: nil, timeout: nil) ⇒ Puppeteer::JSHandle
- #wait_for_navigation(timeout: nil, wait_until: nil) ⇒ Object
- #wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil) ⇒ Object
- #wait_for_timeout(milliseconds) ⇒ Object
- #wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil) ⇒ Object
Constructor Details
#initialize(frame_manager, parent_frame, frame_id, client) ⇒ 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, parent_frame, frame_id, client) @frame_manager = frame_manager @parent_frame = parent_frame @id = frame_id @detached = false @has_started_loading = false @loader_id = '' @lifecycle_events = Set.new @child_frames = Set.new if parent_frame parent_frame._child_frames << self end update_client(client) end |
Instance Attribute Details
#frame_manager ⇒ Object
Returns the value of attribute frame_manager.
52 53 54 |
# File 'lib/puppeteer/frame.rb', line 52 def frame_manager @frame_manager end |
#id ⇒ Object
Returns the value of attribute id.
52 53 54 |
# File 'lib/puppeteer/frame.rb', line 52 def id @id end |
#lifecycle_events ⇒ Object
Returns the value of attribute lifecycle_events.
52 53 54 |
# File 'lib/puppeteer/frame.rb', line 52 def lifecycle_events @lifecycle_events end |
#loader_id ⇒ Object
Returns the value of attribute loader_id.
52 53 54 |
# File 'lib/puppeteer/frame.rb', line 52 def loader_id @loader_id end |
#main_world ⇒ Object
Returns the value of attribute main_world.
52 53 54 |
# File 'lib/puppeteer/frame.rb', line 52 def main_world @main_world end |
#puppeteer_world ⇒ Object
Returns the value of attribute puppeteer_world.
52 53 54 |
# File 'lib/puppeteer/frame.rb', line 52 def puppeteer_world @puppeteer_world end |
Instance Method Details
#_client ⇒ Object
33 34 35 |
# File 'lib/puppeteer/frame.rb', line 33 def _client @client end |
#add_script_tag(url: nil, path: nil, content: nil, type: nil, id: nil) ⇒ Object
199 200 201 |
# File 'lib/puppeteer/frame.rb', line 199 def add_script_tag(url: nil, path: nil, content: nil, type: nil, id: nil) @main_world.add_script_tag(url: url, path: path, content: content, type: type, id: id) end |
#add_style_tag(url: nil, path: nil, content: nil) ⇒ Object
206 207 208 |
# File 'lib/puppeteer/frame.rb', line 206 def add_style_tag(url: nil, path: nil, content: nil) @main_world.add_style_tag(url: url, path: path, content: content) end |
#child_frames ⇒ Object
186 187 188 |
# File 'lib/puppeteer/frame.rb', line 186 def child_frames @child_frames.to_a end |
#click(selector, delay: nil, button: nil, click_count: nil) ⇒ Object
214 215 216 |
# File 'lib/puppeteer/frame.rb', line 214 def click(selector, delay: nil, button: nil, click_count: nil) @puppeteer_world.click(selector, delay: delay, button: , click_count: click_count) end |
#content ⇒ String
156 157 158 |
# File 'lib/puppeteer/frame.rb', line 156 def content @puppeteer_world.content end |
#detach ⇒ Object
338 339 340 341 342 343 344 345 346 |
# File 'lib/puppeteer/frame.rb', line 338 def detach @detached = true @main_world.detach @puppeteer_world.detach if @parent_frame @parent_frame._child_frames.delete(self) end @parent_frame = nil end |
#detached? ⇒ Boolean
190 191 192 |
# File 'lib/puppeteer/frame.rb', line 190 def detached? @detached end |
#eval_on_selector(selector, page_function, *args) ⇒ !Promise<(!Object|undefined)> Also known as: Seval
‘$eval()` in JavaScript.
126 127 128 |
# File 'lib/puppeteer/frame.rb', line 126 def eval_on_selector(selector, page_function, *args) @main_world.eval_on_selector(selector, page_function, *args) end |
#eval_on_selector_all(selector, page_function, *args) ⇒ !Promise<(!Object|undefined)> Also known as: SSeval
‘$$eval()` in JavaScript.
138 139 140 |
# File 'lib/puppeteer/frame.rb', line 138 def eval_on_selector_all(selector, page_function, *args) @main_world.eval_on_selector_all(selector, page_function, *args) end |
#evaluate(page_function, *args) ⇒ Object
89 90 91 |
# File 'lib/puppeteer/frame.rb', line 89 def evaluate(page_function, *args) @main_world.evaluate(page_function, *args) end |
#evaluate_handle(page_function, *args) ⇒ !Promise<!Puppeteer.JSHandle>
81 82 83 |
# File 'lib/puppeteer/frame.rb', line 81 def evaluate_handle(page_function, *args) @main_world.evaluate_handle(page_function, *args) end |
#execution_context ⇒ Object
75 76 77 |
# File 'lib/puppeteer/frame.rb', line 75 def execution_context @main_world.execution_context end |
#focus(selector) ⇒ Object
221 222 223 |
# File 'lib/puppeteer/frame.rb', line 221 def focus(selector) @puppeteer_world.focus(selector) end |
#goto(url, referer: nil, timeout: nil, wait_until: nil) ⇒ Puppeteer::HTTPResponse
63 64 65 |
# File 'lib/puppeteer/frame.rb', line 63 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
321 322 323 324 325 326 327 |
# File 'lib/puppeteer/frame.rb', line 321 def handle_lifecycle_event(loader_id, name) if name == 'init' @loader_id = loader_id @lifecycle_events.clear end @lifecycle_events << name end |
#handle_loading_started ⇒ Object
329 330 331 |
# File 'lib/puppeteer/frame.rb', line 329 def handle_loading_started @has_started_loading = true end |
#handle_loading_stopped ⇒ Object
333 334 335 336 |
# File 'lib/puppeteer/frame.rb', line 333 def handle_loading_stopped @lifecycle_events << 'DOMContentLoaded' @lifecycle_events << 'load' end |
#has_started_loading? ⇒ Boolean
54 55 56 |
# File 'lib/puppeteer/frame.rb', line 54 def has_started_loading? @has_started_loading end |
#hover(selector) ⇒ Object
228 229 230 |
# File 'lib/puppeteer/frame.rb', line 228 def hover(selector) @puppeteer_world.hover(selector) end |
#inspect ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/puppeteer/frame.rb', line 25 def inspect values = i[id parent_frame detached loader_id lifecycle_events child_frames].map do |sym| value = instance_variable_get(:"@#{sym}") "@#{sym}=#{value}" end "#<Puppeteer::Frame #{values.join(' ')}>" end |
#name ⇒ String
168 169 170 |
# File 'lib/puppeteer/frame.rb', line 168 def name @name || '' end |
#navigated(frame_payload) ⇒ Object
307 308 309 310 311 312 313 314 |
# File 'lib/puppeteer/frame.rb', line 307 def navigated(frame_payload) @name = frame_payload['name'] @url = "#{frame_payload['url']}#{frame_payload['urlFragment']}" # Ensure loaderId updated. # The order of [Page.lifecycleEvent name="init"] and [Page.frameNavigated] is random... for some reason... @loader_id = frame_payload['loaderId'] if frame_payload['loaderId'] end |
#navigated_within_document(url) ⇒ Object
317 318 319 |
# File 'lib/puppeteer/frame.rb', line 317 def navigated_within_document(url) @url = url end |
#oop_frame? ⇒ Boolean
48 49 50 |
# File 'lib/puppeteer/frame.rb', line 48 def oop_frame? @client != @frame_manager.client end |
#page ⇒ Object
44 45 46 |
# File 'lib/puppeteer/frame.rb', line 44 def page @frame_manager.page end |
#parent_frame ⇒ Frame?
178 179 180 |
# File 'lib/puppeteer/frame.rb', line 178 def parent_frame @parent_frame end |
#query_selector(selector) ⇒ !Promise<?Puppeteer.ElementHandle> Also known as: S
‘$()` in JavaScript.
98 99 100 |
# File 'lib/puppeteer/frame.rb', line 98 def query_selector(selector) @main_world.query_selector(selector) end |
#query_selector_all(selector) ⇒ !Promise<!Array<!Puppeteer.ElementHandle>> Also known as: SS
‘$$()` in JavaScript.
148 149 150 |
# File 'lib/puppeteer/frame.rb', line 148 def query_selector_all(selector) @main_world.query_selector_all(selector) end |
#select(selector, *values) ⇒ !Promise<!Array<string>>
235 236 237 |
# File 'lib/puppeteer/frame.rb', line 235 def select(selector, *values) @puppeteer_world.select(selector, *values) end |
#set_content(html, timeout: nil, wait_until: nil) ⇒ Object
163 164 165 |
# File 'lib/puppeteer/frame.rb', line 163 def set_content(html, timeout: nil, wait_until: nil) @puppeteer_world.set_content(html, timeout: timeout, wait_until: wait_until) end |
#Sx(expression) ⇒ !Promise<!Array<!Puppeteer.ElementHandle>>
‘$x()` in JavaScript. $ is not allowed to use as a method name in Ruby.
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/puppeteer/frame.rb', line 108 def Sx(expression) param_xpath = if expression.start_with?('//') ".#{expression}" else expression end query_selector_all("xpath/#{param_xpath}") end |
#tap(selector) ⇒ Object
242 243 244 |
# File 'lib/puppeteer/frame.rb', line 242 def tap(selector) @puppeteer_world.tap(selector) end |
#title ⇒ String
302 303 304 |
# File 'lib/puppeteer/frame.rb', line 302 def title @puppeteer_world.title end |
#type_text(selector, text, delay: nil) ⇒ Object
251 252 253 |
# File 'lib/puppeteer/frame.rb', line 251 def type_text(selector, text, delay: nil) @main_world.type_text(selector, text, delay: delay) end |
#url ⇒ String
173 174 175 |
# File 'lib/puppeteer/frame.rb', line 173 def url @url end |
#wait_for_function(page_function, args: [], polling: nil, timeout: nil) ⇒ Puppeteer::JSHandle
295 296 297 |
# File 'lib/puppeteer/frame.rb', line 295 def wait_for_function(page_function, args: [], polling: nil, timeout: nil) @main_world.wait_for_function(page_function, args: args, polling: polling, timeout: timeout) end |
#wait_for_navigation(timeout: nil, wait_until: nil) ⇒ Object
69 70 71 |
# File 'lib/puppeteer/frame.rb', line 69 def (timeout: nil, wait_until: nil) @frame_manager.(self, timeout: timeout, wait_until: wait_until) end |
#wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil) ⇒ Object
261 262 263 264 |
# File 'lib/puppeteer/frame.rb', line 261 def wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil) query_handler_manager = Puppeteer::QueryHandlerManager.instance query_handler_manager.detect_query_handler(selector).wait_for(self, visible: visible, hidden: hidden, timeout: timeout) end |
#wait_for_timeout(milliseconds) ⇒ Object
269 270 271 |
# File 'lib/puppeteer/frame.rb', line 269 def wait_for_timeout(milliseconds) sleep(milliseconds / 1000.0) end |
#wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil) ⇒ Object
277 278 279 280 281 282 283 284 285 286 |
# File 'lib/puppeteer/frame.rb', line 277 def wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil) param_xpath = if xpath.start_with?('//') ".#{xpath}" else xpath end wait_for_selector("xpath/#{param_xpath}", visible: visible, hidden: hidden, timeout: timeout) end |