2
votes

I am trying to use Watir to get the source code of Facebook after I authenticate using Watir. It gives this specific error.

/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/protocol.rb:158:in `rescue in rbuf_fill': Net::ReadTimeout (Net::ReadTimeout)

I believe that because there are too many AJAX requests in the homepage, webdriver detects it as the page is not fully loaded. So after I logged in, I did this:

p "starts"
Watir::Wait.until {
  browser.div(:'class' => '_586i').exists?
}
p "finishes"

But after it prints "starts" then it gives a timeout error, and doesn't get the source code of the website.

2
This generally happens due to slow internet connection..Arup Rakshit
@ArupRakshit my internet is really fast.Yagiz
for some sites I've set for chrome browser Watir::Wait.until(300), and for firefox Watir::Wait.until(600)Малъ Скрылевъ

2 Answers

1
votes

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.

1
votes

You can force the browser to wait until all ajax calls has been loaded with

sleep(1) until browser.execute_script("return jQuery.active") == 0