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.

有帮助吗?

解决方案

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top