Watir: Get Sometimes a Net::Readtimeout Error by Launching Chrome Browser

Watir script occasionally returning Net::ReadTimeout error

The above error was thrown when the page load time exceeds for 60 seconds so write the following code for page load

client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 120 # seconds
driver = Selenium::WebDriver.for :firefox,http_client: client
b=Watir::Browser.new driver
b.goto "www.google.com"

Now your code would wait for 120 seconds for any page load which has been caused by #click and also wait to load the url by goto method.

Ruby Watir WebDriver Net::ReadTimeout

I've been getting this error for some websites quite a lot after I try to, eg, browser.button.click that is redirecting to another page heavily loaded with Ajax. I found this:

browser.execute_script('document.getElementsByTag('button')[0].click()')
sleep 10

with adjusted sleep (or, much better, .wait_until_present) helps.



Related Topics



Leave a reply



Submit