I am writing an autoit script which tends to open an application [Vision]. When this application is open, the script intends to access an option from the menu which in turn causes another window within the same application to be opened. After configuring and saving some settings, the control is again returned back to the main window in the application [Vision]. I intend to automate this whole thing using auto-it. However, WinActivate() behaves weirdly. I am not sure how to resolve this. Can someone help with it? The following is my code:
Dim $num,$file_name,$opening_file
$num = 1
$file_name = "Hello"
$opening_file = "Vision - [" & $file_name & "]"
Opt("WinTitleMatchMode", 2);
AutoItSetOption ("TrayIconDebug", 1);0-off
Local $pid_handle = ProcessExists("Vision.exe")
If $pid_handle Then
ProcessClose($pid_handle)
Endif
Run("C:\Program Files\Vision.exe")
WinWait("Vision - [Start Page]")
WinWaitActive("Vision")
SendKeepActive("Vision")
sleep(3000)
Send("!f")
Send("n")
WinWait("Capture Options - ")
WinWaitActive("Capture Options - ")
SendKeepActive("Capture Options")
ControlClick("Capture Options","",32494)
sleep(1000)
ControlSetText("Capture Options","",1487,$file_name,"")
Send("{DOWN}")
Send("{Tab}")
WinActivate("Capture Options - ")
ControlClick("Capture Options","",32494)
sleep(1000)
Send("{DOWN}{Tab}")
ControlCommand("Capture Options","",1471,"ShowDropDown","")
If $num = 1 Then
ControlCommand("Capture Options","",1471,"SelectString","1 - here u go")
Elseif $num = 2 Then
ControlCommand("Capture Options","",1471,"SelectString","2 - blah blah..")
EndIf
sleep(2000)
Send("{ENTER}")
ControlClick("Capture Options", "", 1)
sleep(1000)
WinActivate("Vision")
WinWaitActive("Vision")
SendKeepActive("Vision")
sleep(2000)
Send("^!y")
The problems that I face are as follows: a) Though the Vision.exe gets opened using the Run() command, if I happen to click on some other window [GUI/Desktop/Browser], the Vision GUI loses focus and the autoit script gets stuck up at WinWaitActive() line forever and never returns. Isn't the autoit supposed to bring the focus onto the Vision GUI by itself. This way, I see the whole of my automation script fail, if I happen to meddle with the system when it just about happened to open the Vision GUI. How do I fix this? As I said earlier, the flow that needs to happen is: Vision GUI gets opened. Using Alt F or similar commands, I happen to open another dialog box in the GUI. This causes some config settings to be applied. I save and I return back to the vision GUI main window. Now the problem that I face here is that sometimes the Vision GUI's main window is never activated by the autoit and here too I end up waiting on the WinWaitActive line. Isn;t it supposed to have activated Vision main window before reaching the second line?
WinActivate("Vision")
WinWaitActive("Vision")
SendKeepActive("Vision")
sleep(2000)
Send("^!y")
Please help!!