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

I'm using the Win32::GuiTest module to try and automate a little task for myself. My issue is that I run a program with name "FOO". It spawns a child window, also titled "FOO", when it has completed one task. The appearance of this child window signals that the task was done, and simply has an "ok" button on it. I'm trying to use findwindowlike to identify when that child window appears, and complete a series of events, including clicking that "ok" button.

My problem is that I'm not sure how to tell GuiTest to wait until the childwindow appears, nor how to identify only the child "FOO" window, instead of the parent. This is also made complicated by the fact that the parent "FOO" window has an "ok" button on it, and if it is pressed before the task is completed, undesirable results can occur.

Thank you in advance for pondering my question.

Replies are listed 'Best First'.
Re: GUITEST module - FindWindow Question
by batkins (Chaplain) on Oct 21, 2003 at 16:06 UTC
    Well, FindWindowText will return undef if it can't find a window that matches the given criteria. So how about doing something like this:
    my $win; do { select(undef, undef, undef, 500); $win = FindWindowLike(0, "", "FOO"); } until ($win);
    And just replace 500 with the number of milliseconds you'd like to wait between each check.

    The computer can't tell you the emotional story. It can give you the exact mathematical design, but what's missing is the eyebrows. - Frank Zappa
Re: GUITEST module - FindWindow Question
by kelan (Deacon) on Oct 21, 2003 at 20:33 UTC

    The first parameter of FindWindowLike is window ID to start searching from. Usually you probably use 0, so that it starts with the Desktop (which is the ultimate parent of every window). What you should do is first use FindWindowLike to get your main apps window ID, then use that as the first argument in a subsequent call that loops until it finds the new window, like batkins suggested above. Something like this:

    my ($mainapp) = FindWindowLike(0, 'FOO'); my $childwin; while (!$childwin) { select(undef, undef, undef, 0.1); # sleep for 1/10th second ($childwin) = FindWindowLike($mainapp, 'FOO'); } # do stuff with $childwin
    Remember that FindWindowLike returns a list, so you need the parentheses around the variable if you're assigning to a scalar.

    kelan


    Perl6 Grammar Student