我已经构建了一个运行数百页的测试包。我正在使用find_elements来检查页面的呈现。这应该只返回一个数组并继续测试。但是我在最大客户端超时后得到了ReadTimeout:
Net::ReadTimeout: Net::ReadTimeout
/home/ken/.rvm/gems/ruby-2.2.2/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/remote/http/default.rb:107:in `response_for'
/home/ken/.rvm/gems/ruby-2.2.2/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/remote/http/default.rb:58:in `request'
/home/ken/.rvm/gems/ruby-2.2.2/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
/home/ken/.rvm/gems/ruby-2.2.2/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/remote/bridge.rb:649:in `raw_execute'
/home/ken/.rvm/gems/ruby-2.2.2/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/remote/bridge.rb:627:in `execute'
/home/ken/.rvm/gems/ruby-2.2.2/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/remote/bridge.rb:606:in `find_elements_by'
/home/ken/.rvm/gems/ruby-2.2.2/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/common/search_context.rb:84:in `find_elements'
我不希望WebDriver等待,只是继续。
如何抓住或绕过这个以便我的测试完成?
答案 0 :(得分:1)
如果您只想循环浏览页面列表,可以使用begin/rescue/end
块从超时中恢复(并可能打印出相应的消息)。这是一个人为的例子,它寻找一个不存在的页面元素:
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
driver.get 'http://www.iana.org/domains/reserved'
begin
element = driver.find_element(:id, "element_does_not_exist")
rescue => e
puts "element is not found"
end
# a single-line alternative:
# element = driver.find_element(:id, "element_does_not_exist") rescue
driver.quit