Jump to content
Sign in to follow this  
cmb99

ControlSend bugaboo

Recommended Posts

cmb99

[sorry initially posted in the wrong forum]

Having trouble with this script. The first block runs well. The second block is an exact duplicate of the first, but once the dialog comes up "New Login", ControlSend quits, and no text is sent. I can't figure out why the first block would work and not the second. As a test, I deleted the first block, now the second block works, but not the third. It's as if I only get one chance with ControlSend.

; Block 1
Run("C:\Program Files\Java\jre1.5.0\bin\javaw.exe  -cp jts.jar;jcommon-0.9.0.jar;jfreechart-0.9.15.jar -Dsun.java2d.noddraw=true jclient/LoginFrame C:\PROGRA~1\Jts", "C:\PROGRA~1\Jts")
If WinWait("New Login") Then
    ControlSend("New Login", "", "", "XXXX{TAB}XXXX{ENTER}", 0)
EndIf
If WinWait("Universal Account UXXX") Then
    WinSetState("Universal Account UXXXX", "", @SW_MINIMIZE)
EndIf

; Block 2
Run("C:\Program Files\Java\jre1.5.0\bin\javaw.exe  -cp jts.jar;jcommon-0.9.0.jar;jfreechart-0.9.15.jar -Dsun.java2d.noddraw=true jclient/LoginFrame C:\PROGRA~1\Jts", "C:\PROGRA~1\Jts")
If WinWait("New Login") Then
    ControlSend("New Login", "", "", "XXXX{TAB}XXXX{ENTER}", 0)
EndIf
If WinWait("Universal Account UXXX") Then
    WinSetState("Universal Account UXXX", "", @SW_MINIMIZE)
EndIf

; Block 3
Run("C:\Program Files\Java\jre1.5.0\bin\javaw.exe  -cp jts.jar;jcommon-0.9.0.jar;jfreechart-0.9.15.jar -Dsun.java2d.noddraw=true jclient/LoginFrame C:\PROGRA~1\Jts", "C:\PROGRA~1\Jts")
If WinWait("New Login") Then
    ControlSend("New Login", "", "", "XXXX{TAB}XXXX{ENTER}", 0)
EndIf
If WinWait("Universal Account UXXX") Then
    WinSetState("Universal Account UXXX", "", @SW_MINIMIZE)
EndIf
Exit
Edited by cmb99

Share this post


Link to post
Share on other sites
MHz

As to launching 3 exact same blocks of code, to the same program. You may need to use WinWaitActive and possibly Send to deal with the active window, else AutoIt maybe torn between the 3? Another alternative, could be to rename each window to make them distinct. You can continue to use them reliably with Control*() functions then.

Share this post


Link to post
Share on other sites
cmb99

As to launching 3 exact same blocks of code, to the same program. You may need to...

Close, it is actually running the same program three times, multiple instances. I don't see why they should interfere. The minimize command after the first block works, BTW, so I think it si successful.

Share this post


Link to post
Share on other sites
cmb99

In fact, this code works. IT is only because, I am attempting to ultimately (haven't tried it yet) get this script to work when the PC is locked, that I am experimenting with ControlSend.

Run("C:\Program Files\Java\jre1.5.0\bin\javaw.exe  -cp jts.jar;jcommon-0.9.0.jar;jfreechart-0.9.15.jar -Dsun.java2d.noddraw=true jclient/LoginFrame C:\PROGRA~1\Jts", "C:\PROGRA~1\Jts")
WinWaitActive("New Login")
Send("XXXX")
Send("{TAB}", 0)
Send("XXXX")
Send("{ENTER}",0)
WinWaitActive("Universal Account UXXX")
WinSetState("Universal Account UXXX", "", @SW_MINIMIZE)
Run("C:\Program Files\Java\jre1.5.0\bin\javaw.exe  -cp jts.jar;jcommon-0.9.0.jar;jfreechart-0.9.15.jar -Dsun.java2d.noddraw=true jclient/LoginFrame C:\PROGRA~1\Jts", "C:\PROGRA~1\Jts")
WinWaitActive("New Login")
Send("XXXX")
Send("{TAB}", 0)
Send("XXXX")
Send("{ENTER}",0)
WinWaitActive("Universal Account UXXX")
WinSetState("Universal Account UXXX", "", @SW_MINIMIZE)
Run("C:\Program Files\Java\jre1.5.0\bin\javaw.exe  -cp jts.jar;jcommon-0.9.0.jar;jfreechart-0.9.15.jar -Dsun.java2d.noddraw=true jclient/LoginFrame C:\PROGRA~1\Jts", "C:\PROGRA~1\Jts")
WinWaitActive("New Login")
Send("XXXX")
Send("{TAB}", 0)
Send("XXXX")
Send("{ENTER}",0)
WinWaitActive("Universal Account UXXX")
WinSetState("Universal Account UXXX", "", @SW_MINIMIZE)
Edited by cmb99

Share this post


Link to post
Share on other sites
MHz

As active windows does work, then the concept of renaming the windows with WinSetTitle() will allow the distinction between them should allow Control*() functions to work correctly. WinGetHandle() could be another idea to use?

Share this post


Link to post
Share on other sites
cmb99

As active windows does work, then the concept of renaming the windows with WinSetTitle() will allow the distinction between them should allow Control*() functions to work correctly. WinGetHandle() could be another idea to use?

<{POST_SNAPBACK}>

I didn't know I could use WinSetTitle on a program created by someone else. Will try. How fo I get WinGetHandle for Java objects? Window Spy only gives me a title and a class (which does not work on its own BTW).

Share this post


Link to post
Share on other sites
cmb99

Ok WinSetTitle does not work. But, interestingly, if I use:

;Second block
Run("C:\Program Files\Java\jre1.5.0\bin\javaw.exe  -cp jts.jar;jcommon-0.9.0.jar;jfreechart-0.9.15.jar -Dsun.java2d.noddraw=true jclient/LoginFrame C:\PROGRA~1\Jts", "C:\PROGRA~1\Jts")
If WinWait("New Login") Then
    MsgBox(1, "Test", "Got Here!")   ; <====
    ControlSend("New Login", "", "", "XXXX{TAB}XXXX{ENTER}", 0)
EndIf
If WinWait("Universal Account UXXX") Then
    WinSetState("Universal Account UXXX", "", @SW_MINIMIZE)
EndIf

as the second block, and I hit CANCEL at the MsgBox, script execution resumes normally, until the third block. Seems like a bug?

Share this post


Link to post
Share on other sites
MHz

You could replace the msgbox with a Sleep(). It does not mean it is a bug. It could mean that the window is not prepared to handle the input at that time. Another option is to increase the WinWaitDelay. This options allow for a fine tune of operation. Normally it is set at 250. You can increase to add more reliability.

Opt("WinWaitDelay", 250)

Automation sometimes is not a straight forward concept. I believe java applications are alittle slow. So AutoIt may need to be slowed a bit to respond to it? It is good that you found the problem.

You can also use ControlSendText() to send text to the control and also for the sake of checking, use ControlGetText().

Yep, it's all good fun.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×