M
Michael Kelly
------_=_NextPart_001_01C59992.3C23E412
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
So, I'm clear on how to attach to events:
=20
@ie =3D WIN32OLE.new( 'InternetExplorer.Application' )
browserEvents =3D WIN32OLE_EVENT.new( @ie, 'DWebBrowserEvents2' )
browserEvents.on_event { |*args| eventHandler( *args ) }
=20
But how does one detach from events?
=20
I'm working on a little utility that will generate Watir scripts using
IE automation. In the following code I am attaching to the browser
events to capture when a new HTML document is loaded. When a document
is loaded I want to attach to the document's events. When a new
document is loaded I want to detach from the old document's events.
=20
Here's the code so far. At the moment, each newly loaded document adds
to a growing list of event handlers, causing each click to produce
multiple calls to printClickStatement.
=20
Thanks,
=20
-=3Dmichael=3D-
=20
#requires
require 'win32ole'
=20
##//////////////////////////////////////////////////////////////////////
///////////////////////////////
##
## Main WatirMaker class. It handles the IE automation, which primarily
means event handling.
##
##//////////////////////////////////////////////////////////////////////
///////////////////////////////
class WatirMaker=20
=20
=20
##//////////////////////////////////////////////////////////////////////
////////////////////////////
##
## Initializer executed when "new" is called.
##
=20
##//////////////////////////////////////////////////////////////////////
////////////////////////////
def initialize
=20
end
=20
=20
##//////////////////////////////////////////////////////////////////////
////////////////////////////
##
## Handles all events from the browser and the HTML document.
##
=20
##//////////////////////////////////////////////////////////////////////
////////////////////////////
def eventHandler( event, *args )
case event
when "BeforeNavigate2"
webBrowser =3D args[0]
url =3D args[1]
frameName =3D args[3]
=20
if frameName =3D=3D ""
@webBrowsers =3D Hash.new
if @documentEventHandlers !=3D nil
@documentEventHandlers.each_value { |value|
value.on_event( 'onclick' ) {} }
end
@documentEventHandlers =3D Hash.new
end
=20
@webBrowsers =3D webBrowser printNavigateCommen...20 ------_=_NextPart_001_01C59992.3C23E412--
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
So, I'm clear on how to attach to events:
=20
@ie =3D WIN32OLE.new( 'InternetExplorer.Application' )
browserEvents =3D WIN32OLE_EVENT.new( @ie, 'DWebBrowserEvents2' )
browserEvents.on_event { |*args| eventHandler( *args ) }
=20
But how does one detach from events?
=20
I'm working on a little utility that will generate Watir scripts using
IE automation. In the following code I am attaching to the browser
events to capture when a new HTML document is loaded. When a document
is loaded I want to attach to the document's events. When a new
document is loaded I want to detach from the old document's events.
=20
Here's the code so far. At the moment, each newly loaded document adds
to a growing list of event handlers, causing each click to produce
multiple calls to printClickStatement.
=20
Thanks,
=20
-=3Dmichael=3D-
=20
#requires
require 'win32ole'
=20
##//////////////////////////////////////////////////////////////////////
///////////////////////////////
##
## Main WatirMaker class. It handles the IE automation, which primarily
means event handling.
##
##//////////////////////////////////////////////////////////////////////
///////////////////////////////
class WatirMaker=20
=20
=20
##//////////////////////////////////////////////////////////////////////
////////////////////////////
##
## Initializer executed when "new" is called.
##
=20
##//////////////////////////////////////////////////////////////////////
////////////////////////////
def initialize
=20
end
=20
=20
##//////////////////////////////////////////////////////////////////////
////////////////////////////
##
## Handles all events from the browser and the HTML document.
##
=20
##//////////////////////////////////////////////////////////////////////
////////////////////////////
def eventHandler( event, *args )
case event
when "BeforeNavigate2"
webBrowser =3D args[0]
url =3D args[1]
frameName =3D args[3]
=20
if frameName =3D=3D ""
@webBrowsers =3D Hash.new
if @documentEventHandlers !=3D nil
@documentEventHandlers.each_value { |value|
value.on_event( 'onclick' ) {} }
end
@documentEventHandlers =3D Hash.new
end
=20
@webBrowsers =3D webBrowser printNavigateCommen...20 ------_=_NextPart_001_01C59992.3C23E412--