Like you, I'm running dwimperl on Windows 7 Home Premium 64-bit. When I tried running the code, the printed result was blank and the calculator never did do anything.

To make a long story short, I ended up tweaking the code to get it to work. I believe that the calculator app in Windows 7 must be designed differently that the calculator app in previous Windows version.

For those that want to gory details and my tweaked version of the code, here's a summary my debug process. (Also, some of the info might be useful for others wanting to use Win32::GuiTest to automate applications.)

First, I decided to double-check the version of Win32::GuiTest that is in dwimperl. That version is 1.58. Since the example code was from version 1.60, I updated my Win32::GuiTest module to 1.60. Still no luck.

Then I took a look at the code for the 'keyboard' portion as well as the perldoc for Win32::GuiTest. Since I never saw any activity in the calculator app, I figured that the calls to simulate keyboard input was not working correctly. When I changed the calls to PushButton to SendKeys, then the script really did get the calculator app to behave correctly.

However, the printed result from the script was blank. After a bit of testing, I changed to the printf line to be in a loop looking for a window whose text contained only digits and printed that as the result. That fixed the 'keyboard' section of the code.

Onto debugging the 'mouse' section. At one point I thought that since I had my calculator app defaulting to the scientific mode instead of standard mode was the source of the problem. Tested both modes, but there was no difference.

I tried printing out the text from each child window object, but didn't see anything matched the calculator button labels. So I figured that I needed more information about the components of the calculator app. Some time ago I had looked into AutoIt Script and still had it installed. So I used their AutoIt Window Info Tool, which helped me get the window IDs of the needed buttons. So I tweaked the code to look for those IDs. Again, the printed result was blank. So I reused the same loop that I used from the 'keyboard' section.

Below is the final version of the code that worked on my system. Not sure if this will work on any other versions of Windows 7 or earlier versions of the Windows OS.

#!perl -w # # Written by Gabor Szabo <gabor@pti.co.il> # An example how to access the built in calculator (calc.exe) of Windo +ws. # This code assumes your calulator defaults to the Standard view (and +not the Scientific) use strict; use warnings; use Win32::GuiTest qw(:ALL); if (not @ARGV or ($ARGV[0] ne "keyboard" and $ARGV[0] ne "mouse")) { die "Usage: $0 [keyboard|mouse]\n" } system "start calc.exe"; sleep(1); my @windows = FindWindowLike(undef, "Calculator"); if (not @windows) { die "Could not find Calculator\n"; } if (@windows > 1) { die "There might be more than one Calculators running\n"; } if ($ARGV[0] eq "keyboard") { SendKeys('7'); sleep(1); SendKeys('\*'); sleep(1); SendKeys('5'); sleep(1); SendKeys('='); sleep(2); # Catch the content of the first child, # At this point we can only hope that this is the child that holds the + result # as it does not have a title, maybe it has a type that we can check ? my @children = GetChildWindows($windows[0]); foreach my $child (@children) { printf "Result: %s\n",WMGetText($child) if (WMGetText($child) =~ m/ +^\d+$/s); } SendKeys("%{F4}"); # Alt-F4 to exit } if ($ARGV[0] eq "mouse") { my ($left, $top, $right, $bottom) = GetWindowRect($windows[0]); # find the appropriate child window and click on it my @children = GetChildWindows($windows[0]); foreach my $id (qw(137 92 135 121)) { my ($c) = grep {$id == GetWindowID($_)} @children; my ($left, $top, $right, $bottom) = GetWindowRect($c); MouseMoveAbsPix(($right+$left)/2,($top+$bottom)/2); SendMouse("{LeftClick}"); sleep(1); } foreach my $child (@children) { printf "Result: %s\n",WMGetText($child) if (WMGetText($child) =~ m/ +^\d+$/s); } MouseMoveAbsPix($right-10,$top+10); # this probably depends on the re +solution sleep(2); SendMouse("{LeftClick}"); }

In reply to Re: Problems with WIN32::GUITEST by dasgar
in thread Problems with WIN32::GUITEST by newtondavide

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.