user3063045 user3063045 - 27 days ago 16
Ruby Question

WebDriver Selenium ReadTimeout on Find_Elements

I've built a test pack that runs thru hundreds of pages. I'm using find_elements to check the rendering of the page. This should just return an array and continue the test. However I'm getting ReadTimeout after the max client timeout:

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'


I don't want WebDriver to wait, just continue along.

How can I catch or bypass this so that my test completes?

Answer

If you just want to keep cycling through your list of pages, you can use a begin/rescue/end block to recover from the timeout (and possibly print out an appropriate message). Here's a contrived example that looks for a page element that doesn't exist:

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
Comments