views:

433

answers:

1

I recently did a fresh install of Windows 7. I installed Ruby 1.8.6 and Watir via RubyGems. When I try to run a Watir script, IE opens and the first page is called, but the problem seems to be that the script doesn't wait for the page to finish loading (which it's always done in the past). Subsequent lines in the script try to access page elements that haven't loaded yet. Is anyone else having this problem?

A: 

I had the same issue and noticed that I would either get the return from the about:blank window (so the DOM was empty) or the ie.ie was throwing WIN32OLE exceptions for every method. It's acting like it's losing the document completely so I worked around it by reattaching to the window by handle:

module Watir
  class IE
    alias :old_goto :goto
    def goto(*args)
      hwnd = ie.hwnd
      old_goto *args
      _attach_init(:hwnd, hwnd)
    end
  end
end

note: this is assuming Watir::IE.new. If you're using Watir::IE.new_process there are other published workarounds you'll need or you'll encounter a different set of errors

Hugh