lib/smart_driver.rb in smart_driver-1.2.0 vs lib/smart_driver.rb in smart_driver-1.2.1
- old
+ new
@@ -10,13 +10,17 @@
def initialize(url=nil, browser=:chrome)
@__driver__ = Selenium::WebDriver.for(browser)
go(url) if url
end
- def go(url)
+ def go(url, t=10, &block)
logging :info, "visiting #{url}..."
@__driver__.navigate.to(url)
+ if block_given?
+ wait = Selenium::WebDriver::Wait.new(timeout: t)
+ wait.until(&block)
+ end
end
def reload
@__driver__.navigate.refresh
end
@@ -61,16 +65,14 @@
class Selenium::WebDriver::Element
include SmartDriver::CommonInterface
alias :origin_click :click
- def click(n=20)
+ def click(t=10, &block)
origin_click()
if block_given?
- n.times do
- break if yield()
- sleep 0.5
- end
+ wait = Selenium::WebDriver::Wait.new(timeout: t)
+ wait.until(&block)
end
end
def fill(text)
$focus = self