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

1

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.goto("http://www.w3schools.com/js/tryit_view.asp?filename=tryjs_confirm")
iewin=Watir::IE.attach(:url, /w3schools/)
iewin.bring_to_front
iewin.maximize
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
txt1=iewin.clickprompt("OK")
puts txt1

iewin.close

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.

watir
asked on Stack Overflow Apr 12, 2011 by ajazz • edited Apr 12, 2011 by Chuck van der Linden

3 Answers

2

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,

Dave

answered on Stack Overflow Apr 12, 2011 by Dave McNulla
0

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.

0

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?
  begin
    !!(@ie.name =~ /Internet Explorer/)
  rescue WIN32OLERuntimeError
    false
  end
end

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

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

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

answered on Stack Overflow Jul 25, 2011 by Tom

User contributions licensed under CC BY-SA 3.0