Help needed - Script is not running in Windows XP

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
aqua267
Junior Coder
Posts: 27
Joined: Thu Aug 19, 2010 7:57 pm

Help needed - Script is not running in Windows XP

Post by aqua267 » Fri Jan 14, 2011 9:23 pm

Hello,
My scripts work well in Windows Vista. I am using a dual monitor where I have Mjtnet open in one window and my windows application running in other. I have a windows XP machine where I want these scripts to run. Its a single monitor and I am having issues here.
Please help!

Thanks.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Fri Jan 14, 2011 10:00 pm

What are the issues?

Please be very specific. Are there error messages displayed?
How is the behavior different from what you expect?

aqua267
Junior Coder
Posts: 27
Joined: Thu Aug 19, 2010 7:57 pm

Post by aqua267 » Fri Jan 14, 2011 11:16 pm

The message I see is
Error in : Script name
Line: - Specified Window Not Present
Any Subsequent Key Sends In Scripts may cause Exceptions.

I believe it fails to recognize the Setfocus commands. Since my application does not get highlighted, the further commands I pass from scripts is not being recognized.
For example, my script will do something like
SetFocus>Set focus in mainform
Send commands to open a child window or place cursor in the mainform to send some text

Since Setfocus is not working, any commands sent later do not work as well. However the same script works well in Windows Vista (dual monitor not sure if that has any impact).

Thanks for any help/suggestions with this.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Mon Jan 17, 2011 1:19 pm

Line: - Specified Window Not Present
In all cases where I have seen this, the message was correct - i.e. The window REALLY WASN'T OPEN. So of course the SetFocus command cannot focus a window that doesn't exist.


I suspect there are enough differences in your two machines that timing issues are coming into play. I.e. the dual monitor machine may be more powerful and things are happening faster.

Do you have a WaitWindowOpen command to check to see if the window you *think* is opening is truly opening? Always check after using window commands for a failure like this:

Code: Select all

//Set a timeout for how long to wait for windows to open/close
Let>WW_TIMEOUT=10
WaitWindowOpen>Notepad*
//If the window didn't open in *timeout* seconds, goto a label
IF>WW_RESULT=FALSE,WindowNotFound
Wait>0.5
SetFocus>Notepad*

User avatar
JRL
Automation Wizard
Posts: 3517
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Jan 17, 2011 2:06 pm

Another possibility might be that the window name is not exactly the same on the two machines.

A wild card character (*) can be used when window names might be close but not identical. For example, when opening a text file in Notepad the file name displays as part of the Notepad window name. But the word "Notepad" always displays in a Notepad window. You can SetFocus> to any Notepad window regardless of the file name by restricting the name to a partial, leaving out the file name portion and using the wild card character.

SetFocus>Notepad*

aqua267
Junior Coder
Posts: 27
Joined: Thu Aug 19, 2010 7:57 pm

Post by aqua267 » Mon Jan 17, 2011 3:45 pm

I run the scripts after opening the main screen. I manually open the application main window and run the scripts to open child windows in this application.

Before passing a command to open a child window, I check whether the main window is open. (I can see the window is open since I manually opened it. It is minimized). My problem is that the setfocus>mainscreen does not work. Hence the subsequent commands to open child window does not work.

I included the test script from your last comment. Even if the main window is open, the script always returns WindowNotFound.

I did a quick test outside my application:

IfWindowOpen>notepad*,doNotePad
Wait>3
Label>doNotePad
MessageModal>WindowFound

Even if notepad is not open, this script returns WindowFound. I am so confused. I am not sure how to proceed.

aqua267
Junior Coder
Posts: 27
Joined: Thu Aug 19, 2010 7:57 pm

Post by aqua267 » Mon Jan 17, 2011 3:47 pm

Thanks for your reply. I am using the wildcard to setfocus. However that does not work. I've tried to include more details in my comment. I would appreciate any help!
JRL wrote:Another possibility might be that the window name is not exactly the same on the two machines.

A wild card character (*) can be used when window names might be close but not identical. For example, when opening a text file in Notepad the file name displays as part of the Notepad window name. But the word "Notepad" always displays in a Notepad window. You can SetFocus> to any Notepad window regardless of the file name by restricting the name to a partial, leaving out the file name portion and using the wild card character.

SetFocus>Notepad*

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Mon Jan 17, 2011 4:29 pm

IfWindowOpen>notepad*,doNotePad
Wait>3
Label>doNotePad
MessageModal>WindowFound

Even if notepad is not open, this script returns WindowFound
The way your code is written, yes it would. If the "IfWindowOpen" command returns "FALSE" then it simply continues executing commands, so it does the Wait>3 and then it does the MessageModal>

You would need to write it this way:

Code: Select all

IfWindowOpen>Notepad*
  MessageModal>WindowFound
Else
  MessageModal>Window NOT Found
Endif
Double check all your references to window titles, as they ARE case sensitive! Notepad* is NOT the same as notepad*

Use the Tools -->View System Windows utility from within Macro Scheduler when your main application is running. Then you can cut/paste the actual window title. And as always, using the asterisk wildcard is usually recommended.

aqua267
Junior Coder
Posts: 27
Joined: Thu Aug 19, 2010 7:57 pm

Post by aqua267 » Mon Jan 17, 2011 4:46 pm

Thanks again.
Here's a portion of my code:
Let>username=[email protected]
Let>passwd=test

Change Directory>C:\Go to Directory path where application is installed
ExecuteFile>Test.exe , Key
Wait>2.0
//The code below passes a user credential to the Authentication (Login page)
IfWindowOpen>Authentication*
SetFocus>Authentication*
Press Shift
Press tab
Release Shift
Wait>0.2
Press Delete
Wait>1.0
Send>username
Wait>1.0
Press Tab
Wait>1.0
Send>passwd
Wait>1.0
Press Alt
Send>L
Release Alt
Else
MessageModal>>Authentication Window Not Found
EndIF
//Once Login successful, the main form of the application opens.
Wait>2.0
IfWindowOpen>MainForm*
Wait>15
SetFocus>MainForm*
Wait>2
Press Alt
Send>n
Release Alt (Alt +N is to open a child window to test something)
Else
MessageModal>Mainform Not Found
EndIf

Authentication window works fine. However the last part (Alt +N) to the main window never opens the child window. IfWindowOpen succeeds and there is a pause for 15 seconds for the main form to load, then the focus goes away. SetFocus>MainForm* does not work. I've verified the names are specified correct. At this stage, MainForm Not found does not pop up since it succeeded before.
I hope my explanation is understandable. please ask me if there are any other questions.

Update: I ran the same script in Vista and it appears to be working fine.

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

Post by Marcus Tettmar » Mon Jan 17, 2011 5:00 pm

Sounds like there is another window on the system somewhere (possibly hidden) with the word "mainform" in it.

Try to be more specific with the window title. Also try setting WF_TYPE to visible windows or non-child windows only. Or use RegEx for a more specific match. If possible specify the entire title for an exact match without using the asterisk.

See the section "Be Specific" in:
http://www.mjtnet.com/blog/2008/10/27/t ... le-macros/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

aqua267
Junior Coder
Posts: 27
Joined: Thu Aug 19, 2010 7:57 pm

Post by aqua267 » Mon Jan 17, 2011 7:24 pm

Scripts work fine after setting WF_TYPE=2. Looks like there are some hidden windows. Thanks much for all your suggestions.

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