in reply to How do I add a timeout to Win32::IEAutomation click method

And what trouble are you having?

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

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

Replies are listed 'Best First'.
Re^2: How do I add a timeout to Win32::IEAutomation click method
by Redbeard36 (Initiate) on Apr 07, 2014 at 12:10 UTC
    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

        This seemed like a lot, until I worked through making it work. I'm glad for the help, as it would've taken me forever to figure this out. I knew that IEAutomation used OLE as its base, but didn't know how to adjust it, and also didn't know about monkeypatching. Surprisingly, I had read most of the items in your Win32 info during other automation. Like I said before I am very new to this.

        Sorry for the n00b questions, and thanks again for all the help.