http://qs1969.pair.com?node_id=1019128

BrianP6 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

Hopefully this will be relatively straight forward, but I'm tearing my hair out at the moment. I am trying to automate a simple lookup to a web page for a game that I'm on. I need to increase my hits to one of my status pages. I have found out that a 'hit' seems to be related to the browser session, and that the best thing to do is to hit the web page, close explorer and wait 30 minutes before trying again. So, I've googled, and found out how to control IE via OLE and use the Events triggered to catch where the DocumentComplete and OnQuit events are triggered. As below

use strict; use Win32::OLE qw(EVENTS); my $URL = "http://REQUIRED WEB PAGE"; my $IE; my $timeout; displaywebpage(); sub Event { my ($Obj,$Event,@Args) = @_; my $IEObject; print "Here is the Event: $Event\n"; if ($Event eq "DocumentComplete") { $IEObject = shift @Args; print "URL: " . $IEObject->Document->URL . "\n"; print "Now quit IE\n"; $IE->Quit; } elsif ($Event eq "OnQuit") { Win32::OLE->QuitMessageLoop(); } } sub displaywebpage { $IE = Win32::OLE->new("InternetExplorer.Application") || die "Could not start Internet Explorer.Application\n"; $IE->{visible} = 1; Win32::OLE->WithEvents( $IE, \&Event, 'DWebBrowserEvents2' ); $IE->Navigate($URL); Win32::OLE->MessageLoop(); $timeout = 30*60; # n seconds print "Wait for $timeout seconds\n"; $timeout -= sleep $timeout while $timeout > 0; print "Now start again\n"; displaywebpage(); }

The problem is that the OnQuit event fires before IE quits and even with the OnQuit event handler only terminating the message loop, so that it goes back to the perl script to fire another IE after the timeout, the IE window only really quits at the point that the new window is opened.

I want the IE window to quit, then wait for 30 minutes before opening a new window to do the same thing.

Any wisdom you can supply would be most welcome

Thanks