Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Win32::GuiTest waiting for a window

by primus (Scribe)
on Jan 12, 2004 at 18:20 UTC ( [id://320718]=perlquestion: print w/replies, xml ) Need Help??

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

hey all,

i am using Win32::GuiTest to do some automation for a third party application.

within the perl script, i run the third-party app, and use Win32::GuiTest to click a few options and fill in some fields, and then click a "process" button in the third-party app, which process some data for a good 8 minutes.

once that data is finished processing a message box pops up that says, "complete".

my question is, how can i make my perl script wait for that message box to pop up, and when it does grab focus to that and click "OK"?

i tried putting a while loop to wait for it, but doing so slows my computer down to a crawl, and perl takes 99% cpu usage...

typically without waiting for the msg box, the perl script will terminate once it click the "process" button, but i need it to like go to sleep or something, until the msg box appears.

any thoughts?

thanks monks

Replies are listed 'Best First'.
Re: Win32::GuiTest waiting for a window
by kelan (Deacon) on Jan 12, 2004 at 18:35 UTC

    You're right, you do need to sleep. Here's what I use in one of my programs to wait for a window:

    sub WaitFor { my $win; my $title = shift; while (!defined $win) { select(undef,undef,undef,0.1); # sleep for 1/10th of a second ($win) = FindWindowLike(0, $title); } return $win; }
    This sub takes the window title as a parameter and then just sleeps until that window appears. It doesn't set it to the active window, but you can do that with something like this:
    SetForegroundWindow(WaitFor("Some Title"));

    Update: Remember to keep the parentheses around the $win in the loop, because FindWindowLike returns a list.

    kelan


    Perl6 Grammar Student

      thanks! worked like a charm

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://320718]
Approved by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-04-19 07:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found