lib/gogo_driver.rb in gogo_driver-0.1.3 vs lib/gogo_driver.rb in gogo_driver-0.1.4

- old
+ new

@@ -1,48 +1,48 @@ require 'selenium-webdriver' class GogoDriver - attr_accessor :driver + attr_accessor :__driver__ def initialize(browser=:chrome) - @driver = Selenium::WebDriver.for(browser) + @__driver__ = Selenium::WebDriver.for(browser) end def go(url) logging "[VISITE] #{url}..." - @driver.navigate.to(url) + @__driver__.navigate.to(url) end def reload - @driver.navigate.refresh + @__driver__.navigate.refresh end def find(selector) logging "[FIND] #{selector}..." - @driver.find_element(css: selector) + @__driver__.find_element(css: selector) end # http://stackoverflow.com/questions/11908249/debugging-element-is-not-clickable-at-point-error def scroll(selector) logging "[SCROLL] #{selector}..." element = find(selector) - @driver.driver.execute_script "window.scrollTo(#{element.location.x},#{element.location.y})" + @__driver__.driver.execute_script "window.scrollTo(#{element.location.x},#{element.location.y})" element end def finds(selector) - @driver.find_elements(css: selector) + @__driver__.find_elements(css: selector) end def has?(selector) !!find(selector) rescue Selenium::WebDriver::Error::NoSuchElementError false end def has_text?(text) - !!@driver.find_element({xpath: "//*[text()[contains(.,\"#{text}\")]]"}) + !!@__driver__.find_element({xpath: "//*[text()[contains(.,\"#{text}\")]]"}) rescue Selenium::WebDriver::Error::NoSuchElementError false end def click(selector) @@ -53,11 +53,15 @@ def submit logging "[SUBMIT] ..." $focus.submit if $focus end + def save_html(file_path) + File.open(file_path, 'w') { |f| f.write(@__driver__.page_source) } + end + def method_missing(method, *args, &block) - @driver.respond_to?(method) ? @driver.send(method, *args, &block) : super + @__driver__.respond_to?(method) ? @__driver__.send(method, *args, &block) : super end private def logging(text) puts text