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

I am attempting to add a timeout to clicking a link with Win32::IEAutomation, and am not sure about how to do it. The desired behavior would be that if the page take less than a specified time to load, continue with the script. If it is taking longer then the specified time, send an email notification utilizing an already written subroutine.

  • Comment on How do I add a timeout to Win32::IEAutomation click method

Replies are listed 'Best First'.
Re: How do I add a timeout to Win32::IEAutomation click method
by Anonymous Monk on Apr 05, 2014 at 07:51 UTC

    And what trouble are you having?

    Docs say Click($nowait); so click without waiting, then sleep, then check if its loaded ... :)

      I thought about that route, but wasn't sure of a way to actively check if the page had loaded. I don't see anything in the doc about page state check. I'm a bit new to this and do appreciate the help.

        I don't see anything in the doc about page state check.

        What doc?

        You are aware that Win32::IEAutomation is only half the docs (more like 5%)?

        Win32::IEAutomation uses Win32::OLE to automate InternetExplorer.Application, msdn is where 95% of the docs live, and a whole bunch of that 95% is DOM documentation

        Ok, back to checking if page is loaded, we start where we left off with nowait, so if you go to Win32::IEAutomation and Ctrl+Find in page for "wait" you'll find WaitforDone()

        If you UTSL and look inside of WaitforDone you will see

        sub WaitforDone{ my $self = shift; my $agent = $self->{agent}; while ($agent->Busy || $agent->document->readystate ne "complete") +{ sleep 1; } }

        So you can monkeypatch yourself a $ieauto->WaitforDoneTimeout( 6 );

        sub Win32::IEAutomation::WaitforDoneTimeout { my( $self, $timeout ) = @_; $timeout ||= 0; my $starttime = time; my $agent = $self->{agent}; while( 1 ){ my $loaded = !!( $agent->Busy || $agent->document->readystate +ne "complete" ); return "loaded" if $loaded; sleep 1; if( (time - $starttime) > $timeout ){ return "timedout"; } } return "nuclear explosion"; }

        Also if you started from Click by looking inside https://metacpan.org/source/PRASHANT/Win32-IEAutomation-0.5/lib/Win32/IEAutomation/Element.pm#PWin32::IEAutomation::Element

        sub Click{ my ($self, $nowait) = @_; $self->{element}->click; $self->{parent}->WaitforDone unless $nowait; }

        you'd find WaitforDone , so the circle is complete ... that is ieautomation ;)

        more generic win32 tips