lib/smart_driver.rb in smart_driver-1.0.0 vs lib/smart_driver.rb in smart_driver-1.0.1

- old
+ new

@@ -29,28 +29,38 @@ @__driver__.find_elements(css: selector) rescue Selenium::WebDriver::Error::NoSuchElementError logging :fail, "#{selector} cannot be found" end + def find_by_text(text) + logging :info, "find by text #{text}..." + @__driver__.find_element({xpath: "//*[text()[contains(.,\"#{text}\")]]"}) + rescue Selenium::WebDriver::Error::NoSuchElementError + logging :fail, "element with #{text} cannot be found" + end + + def finds_by_text(text) + logging :info, "finds by text #{text}..." + @__driver__.find_elements({xpath: "//*[text()[contains(.,\"#{text}\")]]"}) + rescue Selenium::WebDriver::Error::NoSuchElementError + logging :fail, "elements with #{text} cannot be found" + end + # http://stackoverflow.com/questions/11908249/debugging-element-is-not-clickable-at-point-error def scroll(selector) logging :info, "scroll to #{selector}..." element = find(selector) exec_js "window.scrollTo(#{element.location.x},#{element.location.y})" element end def has?(selector) !!find(selector) - rescue Selenium::WebDriver::Error::NoSuchElementError - false end def has_text?(text) - !!@__driver__.find_element({xpath: "//*[text()[contains(.,\"#{text}\")]]"}) - rescue Selenium::WebDriver::Error::NoSuchElementError - false + !!find_by_text(text) end def click(selector) logging :info, "click #{selector}..." has?(selector) ? find(selector).click : false @@ -69,9 +79,13 @@ 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 + end + + def switch_window(num) + @__driver__.switch_to.window @__driver__.window_handles[num] end private def logging(sym, text) label = case sym