Class: PhantomMenace::Browser
- Inherits:
-
Object
- Object
- PhantomMenace::Browser
- Defined in:
- lib/phantom_menace/browser.rb
Overview
PhantomMenace::Browser
Creates a Browser that you can interact with. Exposes methods like how you would find a real browser.
Example
browser = PhantomMenace::Browser.new
browser.goto "http://facebook.com"
Look at the API for more methods.
Instance Method Summary collapse
-
#find(sel) ⇒ Object
Uses jQuery’s selector method.
- #find_all_links ⇒ Object
-
#goto(url) ⇒ Object
Navigates to the specified URL.
-
#render(filename = nil) ⇒ Object
Renders the loaded page in the specified path, if path is not given, defaults to the current directory.
Instance Method Details
#find(sel) ⇒ Object
Uses jQuery’s selector method. ‘$(sel)`
38 39 40 41 42 43 44 45 46 |
# File 'lib/phantom_menace/browser.rb', line 38 def find(sel) = { command: "find", data: { selector: sel } } post()["ret"].map do |node| PhantomMenace::Element.new(node) end end |
#find_all_links ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/phantom_menace/browser.rb', line 27 def find_all_links = { command: "find", data: { selector: "a" } } post()["ret"].map do |node| PhantomMenace::Element.new(node) end end |
#goto(url) ⇒ Object
Navigates to the specified URL.
19 20 21 22 23 24 25 |
# File 'lib/phantom_menace/browser.rb', line 19 def goto(url) = { command: "goto", data: { url: url } } post() end |
#render(filename = nil) ⇒ Object
Renders the loaded page in the specified path, if path is not given, defaults to the current directory.
51 52 53 54 55 56 57 58 |
# File 'lib/phantom_menace/browser.rb', line 51 def render(filename = nil) filename ||= File.("../", __FILE__) + "/screenshot.png" = { command: "render", data: { filename: filename } } post() end |