In attempting to add popup support to IE automation I've encountered what
may be a bug in Win32::OLE.  The following code exhibits the problem.

#!/usr/bin/perl -w
use strict;
use Data::Dumper;
use Win32::OLE qw( EVENTS );            # we need Win32::OLE with events
use Time::HiRes qw(gettimeofday);       # provide more accurate timings

$|=1;       # do not buffer

my $self = {};
my $ie = Win32::OLE->new( 'InternetExplorer.Application' ) or 
    die "error";
$ie->{visible} = 1;
Win32::OLE->WithEvents( $ie, \&ie_events, 'DWebBrowserEvents2' );
$self->{ie} = $ie;
print "self after initialization\n" . Dumper( $self );

$self->{popups} = [];
$self->{ts} = $self->{tle} = gettimeofday;
print "navigate to google\n" . Dumper($self);
$ie->navigate( 'http://www.google.com/' );
while(gettimeofday - $self->{ts} < 60){
    Win32::OLE->SpinMessageLoop;        # check for events
    last if( gettimeofday - $self->{tle} > 10 );
}
print "done google\n" . Dumper( $self );

print "\n";
$self->{popups} = [];
$self->{ts} = $self->{tle} = gettimeofday;
print "navigate to popup_tester\n" . Dumper($self);
$ie->navigate( 'http://www.gozer.org/mozilla/popup_tester/' );
while(gettimeofday - $self->{ts} < 60){
    # check for events
    Win32::OLE->SpinMessageLoop;
    # if no events in 10 seconds, declare navigation done
    last if( gettimeofday - $self->{tle} > 10 );
}
print "done popup_tester\n" . Dumper( $self );

sub ie_events(){
    my( $ie, $event, @args ) = @_;
    
    my $tn = gettimeofday();
    $self->{tle} = $tn;
    
    my $te = sprintf '%6.2f', $tn - $self->{ts};
    print "$self $ie $te [$event]\n";

    if( $event eq 'NewWindow2' ) {
            print "self before new window handling\n"; print Dumper($self);
            my $popupself = {};
            my $ie = Win32::OLE->new( 'InternetExplorer.Application' ) or
                die( 'could not start IE on allowed NewWindow2' );
            print "self after new IE application\n"; print Dumper($self);
            $popupself->{ie} = $ie;      # remember ie application
            my $xx = $self->{popups};
            push @{$xx}, $popupself;     # save new IE object
            print "self after push\n"; print Dumper($self);
            #$args[0]->Put( $ie->{application});
            $args[0]->Put( $ie );
            $args[1]->Put( 0 );
    }
}

Curiously the code crashes on the 2nd popup window at
http://www.gozer.org/mozilla/popup_tester/, not the first.  Somewhat
surprisingly, commenting out the push that attempts to save $popupself
allows the code to run to completion.  I'm uncertain why any of this occurs.



Richard Bell
[EMAIL PROTECTED]
 


Reply via email to