in reply to Win32::IEAutomation and existing IE session

Now I was thinking, perhaps there is a way to bring Win32::IEAutomation to connect to an existing IE session (I know that this can be done for Excel instances for example).
Try
package IeExisting; use Win32::IEAutomation; @IeExisting::ISA='Win32::IEAutomation'; sub _startIE{ my ($self, $visible, $maximize) = @_; defined $self->{agent} and return; $self->{agent} = Win32::OLE->GetActiveObject('InternetExplorer.Application') || Win32::OLE->new("InternetExplorer.Application") || die "Could not start Internet Explorer Application through OLE\n"; Win32::OLE->Option(Warn => 0); Win32::OLE->WithEvents($self->{agent}); $self->{agent}->{Visible} = $visible; if ($maximize){ my $clicker = Win32::IEAutomation::WinClicker->new(); $clicker->maximize_ie(); undef $clicker; } return $self; } ...

Replies are listed 'Best First'.
Re^2: Win32::IEAutomation and existing IE session
by DACONTI (Scribe) on Feb 09, 2009 at 10:28 UTC
    Many thanks,
    it was exactly what I was looking for and it works fine!
    Best Regards,
    Davide.
      Hi PMs,

      I too am trying to reuse an IE session but have no success with this:

      use IeExisting; my $ie = IeExisting->new( visible => 1, maximize => 1, warnings => 1); $ie->gotoURL('http://www.google.com');

      This starts up a new IE window rather than finding/connecting to existing session.

      I confirmed it is using the IeExisting constructor (by commenting out the line with "->new" from IeExisting, but then I get an error "Could not start Internet Explorer Application through OLE" when trying to connect to an existing session

      Or am I doing something wrong?

      Suggestions and comments welcome.

      I'm using IE7 on XP.

      Thanks...
        Change the error message to include $^E or Win32::OLE::LastError()