in reply to Getting Win32::IE::Mechanize to wait for responses

Read the MSDN documentation on the Microsoft IE Object Model. There is a Busy property that you can poll. You might want to submit a patch to the author, so the object does the polling itself.

  • Comment on Re: Getting Win32::IE::Mechanize to wait for responses

Replies are listed 'Best First'.
Re^2: Getting Win32::IE::Mechanize to wait for responses
by mickey (Acolyte) on Mar 04, 2005 at 18:01 UTC

    Actually, Win32::IE::Mechanize does do the polling.

    After it calls the click() method on the input object, it calls an internal method called _wait_while_busy, which looks like this:

    sub _wait_while_busy { my $self = shift; my $agent = $self->{agent}; # The documentation isn't clear on this. # The DocumentComplete event roughly says: # the event gets fired (for each frame) after ReadyState == 4 # we might need to check if the first one has frames # and do some more checking. my $sleep = 4; # 0.4; # while ( $agent->{Busy} == 1 ) { $sleep and sleep( $sleep ) } # return unless $agent->{ReadyState}; while ( $agent->{ReadyState} <= 2 ) { $sleep and sleep( $sleep ); } $self->{ $_ } = undef for qw( forms cur_form links images ); return $self->success; }

    It looks like the author tried polling the Busy property, but that didn't work, and is trying the ReadyState property instead. That seems to work when the preceding call is $agent->navigate() (in Win32::IE::Mechanise::get()), but at least on my system it's breaking when the preceding call is $input->click().

    But thanks for the link to the MSDN docs; I'll have a look and see what I can find out.

Re^2: Getting Win32::IE::Mechanize to wait for responses
by allenaaker (Initiate) on Mar 11, 2005 at 19:49 UTC
    Hi, This is my first post at perlmonks.com - if I'm in the wrong place let me know. I have two questions? When I create an object with

    $IE = Win32::OLE->new('InternetExplorer.Application');

    What is retunred to $IE?(Question 1) From the syntax used in other progrmas it looks like a reference to a hash. But when I try and dereference it and print out the key values nothing is ouput to my terminal.

    while( ($key, $value) = each %$IE ) { print "$key => $value\n"; }

    Also, is there any perl specific documentation for this object?(Question 2) Thanks!

      Hello and welcome, allenaaker!

      In principle, there is nothing wrong with posting here, but it is better to start a question at Seekers of Perl Wisdom, as then many more people will see it.

      To your two questions:

      1. The object returned into $IE is a special object that tries to behave mostly like a normal Perl object, but in fact, it is some magical C object that cannot really be inspected. It interfaces to the InternetExplorer.Application object of Windows resp. the Internet Explorer browser.

      2. To find information about the InternetExplorer.Application, see the documentation by Microsoft. There is no Perl specific documentation, but it is not hard to translate the examples in VB into Perl.

Re^2: Getting Win32::IE::Mechanize to wait for responses
by abhaysingh (Initiate) on May 14, 2008 at 06:32 UTC
    you can use
    $ie->{agent}->Document->readyState !~ /complete/i){ sleep(0.5); }
    It will work I am using this...Hope this is useful Any modification suggestions is appreciated Thanks Abhay K. Singh