“object invoked has disconnected from its clients” error message is displayed while working with popup windows

Tag: watir Author: abc3212008007 Date: 2011-03-27

I am trying to work with popup windows. I have gone through the site "http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups". I have modified the "ie-class.rb" by adding the code mentioned in the solution #7 of the site.

Also I have tried the example mentioned below :

require 'watir/ie'
require 'win32ole'

iewin = Watir::IE.new
iewin=Watir::IE.attach(:url, /w3schools/)
iewin.button(:value, "Show a confirm box").click_no_wait
txt = iewin.clickprompt("OK") # waits for popup and click ok
puts txt #prints the popup text
puts txt1


On executing the following code, popups are handled but produces the following error :

C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-1.7.1/lib/watir/ie-class.rb:319:in `method_missing': unknown property or method: `name' (NoMethodError)
    HRESULT error code:0x80010108
      The object invoked has disconnected from its clients.
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-1.7.1/lib/watir/ie-class.rb:319:in `exists?'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-1.7.1/lib/watir/ie-class.rb:406:in `close'
    from popup.rb:50:in `<main>'
Press a button!
You pressed OK!

But when I remove the command "iewin.close", error message is not displayed.

"iewin.close" command closes the browser and then there is nothing for watir to perform then why is the error message displayed.

Please suggest.

Best Answer

It appears that you are using ruby 1.9.2 with Watir. The watir installation page recommends using Ruby 1.8.7. That should fix the problem.

Good luck,



Thanks Dave. One more question i would like to ask is on migrating from Ruby 1.9.2 to 1.8.7, will my tests scripts be affected because I am trying to degrade from the latest to old version. Is there any procedure for doing this or just deleting the existing gem files of 1.9.2 and installing 1.8.7 would be suffice. Please suggest.
Install 1.8.7 in another directory, install the watir gem, make sure your environment variables are up to date, then run your scripts. There are techniques for having multiple versions of Ruby installed at the same time, you can google them.
Hey Dave, After Installing 1.8.7 and running the script, I donot find this error message. Thank you.

Other Answer1

Notice that the output you have is not in order. You are seeing the error from closing the browser, BEFORE the output from your Puts.

Not sure if this is a treading issue or what, but in any event it looks from the output like the window is attempting to close before stuff that is dependent on it has finished. Perhaps try inserting a brief sleep for a second or five right before you try to close the window and see if you are still having issues.


I tried with sleep for 5 seconds before closing the window and the script produces the following error: >ruby popup.rb C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-1.7.1/lib/watir/ie-class.rb:319:in method_missing': unknown property or method: name' (NoMethodError) HRESULT error code:0x800706ba The RPC server is unavailable. from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-1.7.1/lib/watir/ie-class.rb:319:in exists?' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-1.7.1/lib/watir/ie-class.rb:406:in close' from popup.rb:49:in `<main>' Press a button! You pressed OK! >Exit code: 1
All I can say is, it's giving you the file name, and the line numbers.. what's on those lines? what is the code trying to do at the point it has a problem?

Other Answer2

Dug into this a bit. It appears that Ruby 1.9 is throwing a "NoMethodError" instead of a "WIN32OLERuntimeError". The Watir IE code reads as such

def exists?
    !!(@ie.name =~ /Internet Explorer/)
  rescue WIN32OLERuntimeError

To fix this a second rescue can be added to the call

def exists?
    !!(@ie.name =~ /Internet Explorer/)
  rescue WIN32OLERuntimeError
  rescue NoMethodError

I don't know the side effects of adding such a call, but it does suppress the close warning.