Macro can't find WIndows with wildcards

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
dbish
Junior Coder
Posts: 49
Joined: Wed Jan 08, 2003 8:38 am

Macro can't find WIndows with wildcards

Post by dbish » Thu Nov 11, 2004 6:16 am

I have used MSched for about 10 years and have noticed a problem more frequently in the last year - my macros can't find windows with known names with or without wildcards. Hoeever, the problem is not consistent - sometimes my macro finds Microsoft Excel* and other times it won't but will find Excel*. It seems that the space is a problem - many times a fix like searching for Outlook* instead of Outlook Express* will do the trick. Today's script is really stumping me.

Macro goes to web site, inputs stock ticker and waits for website to put up window called File Download. I click yes and when window called Save As appears I input file name to save it into (all of which works fine). I then have a test in case the file already exists in which case another (second) window called Save As appears (with focus) and I say ALT Y to overwrite. I cannot make my macro to focus on this second Save As box and confirm overwrite. THe box appears to have focus but Alt does nothing (and no other window seems affected if it is stray).

As a debugging technique I manually did all the steps until I had inputted the file name. I copies out the the snippet of code to save and approve overwriting into a small temporary macro and ran it - it worked just fine. The exact same code failed on my big macro.

CODE:
Let>CF_OVERWRITE=1
Let>OPTDIR=C:\My Documents\Excel\Options\Backup_QQQ_OEX\
Let>TEMP3DIR=C:\Temp3\
.
.
WaitWindowOpen>File Download
Wait>1
Press ALT
Wait>0.1
Send>S
Wait>0.1
Release ALT
WaitWindowOpen>Save As
Wait>.5
Send>%OPTDIR%%FILENAMEDATE%
Wait>1
SetFocus>Save As*
Wait>1
Press ALT
Wait>0.1
Send>S
Release ALT
Wait>2
IfWindowOpen>Save As*,CLOSEWEBPAGE1
Goto>CONTINUE1
Label>CLOSEWEBPAGE1
SetFocus>Save As*
Wait>.4
Press ALT
Send>Y
Release ALT
Label>CONTINUE1
Wait>4
CopyFile>%OPTDIR%%FILENAMEDATE%.dat,%TEMP3DIR%%FILENAMEDATE%.dat

Any Thoughts?

Dave

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Nov 11, 2004 6:29 am

The exact same code failed on my big macro.
Some thoughts that crossed my mind looking at this:

1. You may think "exact same", but is possible tht code is not exact same, due to possible Trailing Spaces somwhere.

2. Even though code really is "exact same", it is possible that some variables used in the same exact code has different values. Perhaps insert a MessageModal before all commands that use variables to show you the values just before execution (Can also look at logs to see values if you used %variable% formats.).

3. Try using WaitReady>1 after SetFocus> before using Press/Send/Mouse types of commands.

4. Have seen some combo-key functions are case sensitive, ALT-A not the same as ALT-a.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Guest

Post by Guest » Thu Nov 11, 2004 7:35 am

Bob,

Thanks for the quick reply. I tried your initial suggestions without success. I also tried to specifically use the window's handles and still could not get it to work. I am going out of town for 4 days tomorrow. I will have to continue my attempts when I get back.

I appreciate your ideas and VERY QUICK response. Talk to you next week.

Enjoy Veteran's Day!

Dave

User avatar
Captive
Macro Veteran
Posts: 213
Joined: Sun Oct 20, 2002 8:37 pm
Location: Colorado, USA

Post by Captive » Thu Nov 11, 2004 8:18 am

When you "setfocus" a window - it's sometimes required to increase the wait value, as "0.4" may not be long enough.

However, rather than trying to send ALT-Y to the second window, try just pressing space instead (or tab, then space). You may not even have to SetFocus it at all, as it may already be the focused window.

As for the problem "finding" a window, it may be that there are multiple windows that exist with the same wildcard, but the first few are hidden. There is an option to set focus to the first VISIBLE window....
Let>WF_TYPE=2
(and then "SetFocus")
OutLook express is a horrible example of this. It contains many hidden window that use words like "outlook express" in their window names.

In your example, there may be 2 windows called "Save As". When you "setfocus" the second time, it may be trying to set focus back to the first window.

Your example also does not contain any declration for %FILENAMEDATE% ... but as you said, this is a snippet of code, and it could be that it exists in your full script.

If the webpage you are obtaining is a simple one (no frames, etc), check out the HTTPRequest command, which can fetch and save the results from a target page.

An alternative to your logic could be to use MSched to check if the file exists first (IfFileExists command), and then delete (or rename) if it does. That way you can reduce the chance that the second "save as" window will ever appear.

dbish
Junior Coder
Posts: 49
Joined: Wed Jan 08, 2003 8:38 am

Post by dbish » Tue Nov 30, 2004 3:13 pm

I forgot that I had this post out there.

Thanks for the suggestions - I will try them the next time I have a failure (which hasn't happened for several weeks).

Thanks.

Dave

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