module Praline
@author Antoine d’Otreppe
Private Class Methods
# File lib/praline.rb, line 88 def self.browser if @browser.nil? @browser = Selenium::WebDriver.for(:firefox) end @browser end
# File lib/praline.rb, line 96 def self.kill_browser if not @browser.nil? @browser.quit @browser = nil end end
Public Instance Methods
Get the WebDriver itself, for in-depth manipulation @return [Selenium::WebDriver::Driver] the driver
# File lib/praline.rb, line 76 def browser Praline::browser end
Follow the specified link @param [String] link_text the text of the link to follow
# File lib/praline.rb, line 64 def follow(link_text) Praline::browser.find_element(:link, link_text).click end
Get the text of the <h1> of the current page. Will fail if there are several such tags @return [String] the text of the single <h1> tag of the current page
# File lib/praline.rb, line 49 def h1 Praline::browser.find_element(:xpath, "//h1") end
Fill an input with the given text. Also works with <select> and checkbox elements @param [String] name the html name attribute of the target input @param [String] value the text to be put
# File lib/praline.rb, line 36 def input(name, value) Praline::browser.find_element(:name, name).send_keys(value) end
Kill the browser. Call this when you are done with your script
# File lib/praline.rb, line 82 def kill_browser Praline::kill_browser end
Load the given URL in the browser @param [String] url the url to open
# File lib/praline.rb, line 28 def open(url) Praline::browser.get(url) end
Get the options’ text from a specified select @param [String] select_name name of the select you want to poll @return [Array] array of the text values of the options in this select
# File lib/praline.rb, line 56 def options(select_name) select = Praline::browser.find_element(:name, select_name) options = select.find_elements(:tag_name, 'option') options.map {|option| option.text } end
Submit the specified form @param [String] form_name the html name of the form to submit
# File lib/praline.rb, line 70 def submit(form_name) Praline::browser.find_element(:name, form_name).submit end
Get the current page title @return [String] the contents of the <title> tag of the current page
# File lib/praline.rb, line 42 def title Praline::browser.title end