0

这里有什么问题?我想等待下一个任务,直到我的页面完全加载。问题:没有错误,但驱动程序不等待:-(

# wait for page load
wait2 = Selenium::WebDriver::Wait.new(:timeout => 20) # seconds
count = 0
begin
  raise("maximum attempt crossed #{count} times") if count > 3
  wait2.until {
    self.getDriver.execute_script("return document.readyState;") == "complete"
  }
rescue Timeout::Error
  count +=1
  retry
end

#do sth
4

2 回答 2

0

我将处理以下问题:

wait = Selenium::WebDriver::Wait.new(:timeout => 20) # seconds
count = 0
begin
   raise("maximum attempt crossed #{count} times") if count > 3
   # if the page having title 'page_title' is not loaded within 20 seconds
   # time out error will be thrown,which will be handled by the rescue clause.
   wait.until { driver.title == 'page_title' }
rescue Timeout::Error
   count +=1
   retry
end
于 2013-10-31T15:58:08.550 回答
0

这似乎对我有用。

DEFAULT_TIMEOUT = 10

def wait_for_page_to_load(options = {})
    options[:timeout] ||= DEFAULT_TIMEOUT

    wait = Selenium::WebDriver::Wait.new(options)
    wait.until {current_driver.execute_script('var browserState = document.readyState; return browserState;') == "complete" }

end
于 2015-06-18T02:38:19.497 回答