Debugging and ScreenCapture command

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
R2DU
Newbie
Posts: 5
Joined: Mon Jan 19, 2009 2:30 pm
Location: Guildford, UK

Debugging and ScreenCapture command

Post by R2DU » Tue May 19, 2009 9:18 am

Hi Guys,

I've got a newbie issue, which I haven't found the answer for in the forums.
When debugging, how do you get the FindImagePos command to view the webpage (which is what my script is trying to do) and capture that, rather than the debugging window?

This is the portion of the script I'm having problems with - it removes the temporary screen scrape (tescolink.bmp) and then screen captures into a new copy of this file, and finally compares it to a small portion of the screeen which I know represents that it's moved on properly.

When debuging, I cannot get MS to point to the webpage, and I just end up with the ScreenCapture taking a nice snapshot of my script!
How do I prevent this? :(

Label>looparound2
Let>Delay=2
Let>NumFound=0
Wait>Delay
IfFileExists>c:\REX_Files\tescolink.bmp
DeleteFile>c:\REX_Files\tescolink.bmp
Endif
GetScreenRes>X,Y
ScreenCapture>0,0,X,Y,c:\REX_Files\tescolink.bmp
Wait>Delay
FindImagePos>c:\REX_Files\Tesco_Data_Downloads.bmp,c:\REX_Files\tescolink.bmp,0,1,X,Y,NumFound
MessageModal>%NumFound%
If>NumFound>0
goto>exitloop2
ELSE
goto>looparound2
Endif
Label>exitloop2

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue May 19, 2009 12:15 pm

Use a SetFocus command, and also make sure you have Refocus Windows enabled under the Debug menu. This forces the debugger to refocus whatever was last focused at each step, so when you press F8 to activate the FindImagePos command it will switch focus back to the window you are scanning/capturing.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

R2DU
Newbie
Posts: 5
Joined: Mon Jan 19, 2009 2:30 pm
Location: Guildford, UK

Post by R2DU » Tue May 19, 2009 2:36 pm

Sorry Marcus, but things still aren't working out right... :?

This is my updated portion of script:

Label>looparound2
Let>Delay=2
Let>NumFound=0
Wait>Delay
IfFileExists>c:\REX_Files\tescolink.bmp
DeleteFile>c:\REX_Files\tescolink.bmp
Endif
GetScreenRes>X,Y
Let>WIN_USEHANDLE=1
GetWindowHandle>*,WindowName
SetFocus>%WindowName%
ScreenCapture>0,0,X,Y,c:\REX_Files\tescolink.bmp
Wait>Delay
FindImagePos>c:\REX_Files\Tesco_Data_Downloads.bmp,c:\REX_Files\tescolink.bmp,0,1,X,Y,NumFound
If>NumFound>0
goto>exitloop2
ELSE
goto>looparound2
Endif
Label>exitloop2

All seems to be going OK when I'm using the Debugger and stepping through the line using F8.
When I reach the ScreenCapture command however, even though the previous line has set the focus, it doesn't appear to have enough time to screen scrape the webpage I'm after.
I end up with a screen composed of half (or less) of the webpage I wanted and half of the debugging script from MS.
What am I missing?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue May 19, 2009 2:42 pm

Some options:

1. Set a breakpoint after a delay after the ScreenCapture:

ScreenCapture>...
Wait>2
**BREAKPOINT**

Run to breakpoint. You can step some of the way, then hit run and it will run to breakpoint before focusing the editor again. Or run from top to breakpoint. From there you can then step or run again. You can have multiple breakpoints, step from them or run to them and then continue stepping and so on ...

2. Move or resize the editor so that the target window is in view and the editor doesn't conceal it. You could move/resize it during step at the crucial point.

3. Use multiple monitors - if you're not using multiple monitors you are not productive. Research proves that multiple monitors increase productivity. But that's besides the point. With multiple monitors you can put the editor on the secondary monitor and step through the script controlling the app/screen on the primary monitor. Makes debugging sooooooooooo much easier and effective.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

R2DU
Newbie
Posts: 5
Joined: Mon Jan 19, 2009 2:30 pm
Location: Guildford, UK

Post by R2DU » Tue May 19, 2009 2:49 pm

Breakpoint is the trick!
Thanks - just tried it and it works!!! :D

Really appreciate the fast response, I can now get on with the rest of the script!

Simon

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts