Sid78 Posted April 8, 2010 Share Posted April 8, 2010 Hi, I have a scenarion where in which I want to automate a GUI application based on the Text of the window. For example, you are trying to install something by simulation the next key on the GUI and at the end you will get a window which would display either "Install Success" or "Install Failure". In this scenario, I need to wait for window with "Success" OR "Failure" as text. Possible? //For example, //WinWaitActive("WindowName", "Install Success" OR "Install Failure") ) Any existing methods available in AutoIt for this? Thanks, --Sid Link to comment Share on other sites More sharing options...
thawee Posted April 8, 2010 Share Posted April 8, 2010 (edited) Hi, I have a scenarion where in which I want to automate a GUI application based on the Text of the window. For example, you are trying to install something by simulation the next key on the GUI and at the end you will get a window which would display either "Install Success" or "Install Failure". In this scenario, I need to wait for window with "Success" OR "Failure" as text. Possible? //For example, //WinWaitActive("WindowName", "Install Success" OR "Install Failure") ) Any existing methods available in AutoIt for this? Thanks, --Sid Hi Sid, I was just asking this same question. It is possible i answered my own question. Example: If winwaitactive("WindowName", "Install Success") Send("{Enter}") Endif If winwaitactive("WindowName", "Install Failure") Send("{Enter}") Endif I did test it for one window, and it seemed to work, but I am not sure how it will work with a multiple possible responses. Hope This Helps, Take Care Thawee Edited April 8, 2010 by thawee Link to comment Share on other sites More sharing options...
JohnOne Posted April 8, 2010 Share Posted April 8, 2010 There are a few different ways, and it all depends how the window behaves if and when it is created, as to how best for you to deal with it. As well as the above suggestion you should also look at WinWait() WinExists() WinActivate() AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Fulano Posted April 8, 2010 Share Posted April 8, 2010 (edited) This relies on timeouts, and so has the possibility of being nasty slow/hanging if a timeout isn't specifiedIf winwaitactive("WindowName", "Install Success") Send("{Enter}") Endif If winwaitactive("WindowName", "Install Failure") Send("{Enter}") Endif You might try something along these lines:Func _WinWaitActive ($Title, $Text, $Timeout = 0) ;We are basically making a wrapper function If Not IsArray ($Text) Then ;Check for an array of options, if it wasn't an array, then just call WinWaitActive Return WinWaitActive ($Title, $Text, $Timeout) ElseIf Ubound ($Text) = 1 Then ;If there's only 1 thing to check for then just strip that out and pass it to WinWaitActive Return WinWaitActive ($Title, $Text[0], $Timeout) Else Local $Timer = TimerInit () ;Start our timer ;Convert our timeout to miliseconds, so we don't have to do it every time we loop Local $Timeout_MiliSeconds *= 1000 Local $WinHandle = 0 While (TimerDiff ($Timer) < $Timeout_MiliSeconds or $WinHandle) Local $Exists = WinGetText ($Title) ;Tries to get the text from a window matching the title info given, if there is none (yet), returns 0 If $Exists Then ;If a window with that title exists, loop through our text and check for a match For $Item in $Text If StringInStr ($Exists, $Item) Then $WinHandle = WinGetHandle ($Title, $Item) ;If we find a match, grab the handle of the window it came from ;This will serve to drop us out of the loop as well Next EndIf WEnd Return $WinHandle ;This will return 0 if not found, or the window handle if found, just like WinWaitActive EndFunc Edit: EndFunc seems to love hiding when I post Edited April 8, 2010 by Fulano #fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja! Link to comment Share on other sites More sharing options...
Sid78 Posted April 8, 2010 Author Share Posted April 8, 2010 Hi All, Thanks a lot for the suggestions. What I could figure out is there is no direct way of achieving this functionality. Instead, needs to define wrapper functions or add more intelligemce using basic supports provided to achieve this behavior. Thanks --Sid Link to comment Share on other sites More sharing options...
JohnOne Posted April 8, 2010 Share Posted April 8, 2010 I dont thing you would have to do to much just to get the window Try something like this Opt("WinTitleMatchMode", 2) Do Sleep(10) Until WinExists("Success") Or WinExists("Internet") If WinExists("Success") Then MsgBox(0,"Success","Yay") If WinExists("Failure") Then MsgBox(0,"Failure","Booo") AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
MHz Posted April 9, 2010 Share Posted April 9, 2010 What I could figure out is there is no direct way of achieving this functionality. Perhaps the regex support in advanced window handling may do it as it will support "|" which is like using Or. Look in the help file for "Window Titles and Text (Advanced)". I am not sure if it can do regex on the text parameter but you could test it to find if it does. I have used Adlib functionality often for these decisive times or use a loop to handle all windows. Below is an example of of Adlib. $pid = Run('someapp.exe') ; arrrgh, which window will appear. I will use _adlib() AdlibRegister('_adlib') ; scanning for windows here with _adlib() every 250 ms ProcessWaitClose($pid) AdlibUnRegister('_adlib') ; anything else to do else I will exit? Exit Func _adlib() If WinActive("WindowName", "Install Success") Then Send("{Enter}") ElseIf WinActive("WindowName", "Install Failure") Then Send("{Enter}") EndIf EndFunc Link to comment Share on other sites More sharing options...
thawee Posted April 9, 2010 Share Posted April 9, 2010 Perhaps the regex support in advanced window handling may do it as it will support "|" which is like using Or. Look in the help file for "Window Titles and Text (Advanced)". I am not sure if it can do regex on the text parameter but you could test it to find if it does. I have used Adlib functionality often for these decisive times or use a loop to handle all windows. Below is an example of of Adlib. $pid = Run('someapp.exe') ; arrrgh, which window will appear. I will use _adlib() AdlibRegister('_adlib') ; scanning for windows here with _adlib() every 250 ms ProcessWaitClose($pid) AdlibUnRegister('_adlib') ; anything else to do else I will exit? Exit Func _adlib() If WinActive("WindowName", "Install Success") Then Send("{Enter}") ElseIf WinActive("WindowName", "Install Failure") Then Send("{Enter}") EndIf EndFunc Hmmmm..... Am i understanding this code correctly? Does _adlibregister take the function that you have created above and stick it in memory, and runs it independent of the current script until the conditions for its call are satisfied? also i have a question. Is it possible to create an array that will handle all my controls needed for 1 program, so all i have in my code is 1 loop that can handle all my installs and program executions? I realize that i would have to populate the array, and i could prolly do this with config files. Just wondering. Thanks Link to comment Share on other sites More sharing options...
thawee Posted April 9, 2010 Share Posted April 9, 2010 (edited) Perhaps the regex support in advanced window handling may do it as it will support "|" which is like using Or. Look in the help file for "Window Titles and Text (Advanced)". I am not sure if it can do regex on the text parameter but you could test it to find if it does. I have used Adlib functionality often for these decisive times or use a loop to handle all windows. Below is an example of of Adlib. $pid = Run('someapp.exe') ; arrrgh, which window will appear. I will use _adlib() AdlibRegister('_adlib') ; scanning for windows here with _adlib() every 250 ms ProcessWaitClose($pid) AdlibUnRegister('_adlib') ; anything else to do else I will exit? Exit Func _adlib() If WinActive("WindowName", "Install Success") Then Send("{Enter}") ElseIf WinActive("WindowName", "Install Failure") Then Send("{Enter}") EndIf EndFunc Wow, That was exactly what i was looking for. It ran so efficient, and clean I am extremely grateful Thanks!! Edited April 9, 2010 by thawee Link to comment Share on other sites More sharing options...
MHz Posted April 10, 2010 Share Posted April 10, 2010 Does _adlibregister take the function that you have created above and stick it in memory, and runs it independent of the current script until the conditions for its call are satisfied? Look at Misc. Management in the AutoIt help file for AdlibRegister. The explaination is rather clear. Is it possible to create an array that will handle all my controls needed for 1 program, so all i have in my code is 1 loop that can handle all my installs and program executions? I realize that i would have to populate the array, and i could prolly do this with config files. Sure, but is it practical to do and maintain? That is up to your preference. I find install windows as maybe average of 4 to 5 windows to automate which can be done easily with simple strings. If you use Opt('TrayIconDebug', 1) at the top of your script then you can see the line that has issues as you can interpret the strings in the line by hovering over the tray icon. Using arrays can sometimes complicate something simple such as you would only see the array variable in the TrayIconDebug setting and thus debugging is much harder. Here is a template script that I use from SendToA3x. It is one loop to handle all the windows. expandcollapse popup#region - Program_name install script - (Automated with WinExists functions) #include 'Common_Functions.au3' Opt('WinTitleMatchMode', 4) Opt('TrayIconDebug', 1) ; Installer. $executable = 'filename.ext' ; Default group folder in startmenu. $group = '' ; Installation folder in Program Files. $directory = '' ; Allowed time for installation. $allowed = 60 * 1000 ; Run the installer. $pid = _Automated() $time = TimerInit() Do Select Case WinExists('', '') ControlClick('', '', '') Case WinExists('', '') ControlClick('', '', '') Case WinExists('', '') ControlClick('', '', '') Case WinExists('', '') ControlClick('', '', '') Case WinExists('', '') ControlClick('', '', '') Case Else Sleep(250) EndSelect Sleep(10) If TimerDiff($time) > $allowed Then _Abort() Until Not ProcessExists($pid) ; Remove shortcuts. If _Programs('?.lnk') Then ; Relative to programs directory ; Remove Startmenu shortcuts FileDelete('?.lnk') FileDelete('?.lnk') FileDelete('?.lnk') FileDelete('?.lnk') FileDelete('?.lnk') EndIf _Desktop('?.lnk') _QuickLaunch('?.lnk') Exit #endregion Func _Automated($parameters = Default) ; Run the installer in Default Script directory. Dim $executable If $parameters = Default Then $parameters = '' If Not FileExists($executable) And Not FileExists(@ScriptDir & '\' & $executable) Then Exit 1 ElseIf Not FileExists($executable) Then FileChangeDir(@ScriptDir) EndIf If StringRight($executable, 4) = '.msi' Then Return Run('"' & @SystemDir & '\msiexec.exe" /i "' & @WorkingDir & '\' & $executable & '" ' & $parameters) Else Return Run('"' & @WorkingDir & '\' & $executable & '" ' & $parameters) EndIf Return 0 EndFunc Func _Abort() ; close process if exists then exit. Dim $pid If ProcessExists($pid) Then ProcessClose($pid) Exit 2 Else Exit 3 EndIf EndFunc All the intelligent code handling is hidden away in functions and the main body of the script is kept simple. This helps to keep creation and maintenance hopefully to a minimum. Just add the strings copied from Au3Info and then test. (This template is perhaps a little different to the release version as I have updated a little since then). Link to comment Share on other sites More sharing options...
thawee Posted April 14, 2010 Share Posted April 14, 2010 (edited) Look at Misc. Management in the AutoIt help file for AdlibRegister. The explaination is rather clear. Sure, but is it practical to do and maintain? That is up to your preference. I find install windows as maybe average of 4 to 5 windows to automate which can be done easily with simple strings. If you use Opt('TrayIconDebug', 1) at the top of your script then you can see the line that has issues as you can interpret the strings in the line by hovering over the tray icon. Using arrays can sometimes complicate something simple such as you would only see the array variable in the TrayIconDebug setting and thus debugging is much harder. Here is a template script that I use from SendToA3x. It is one loop to handle all the windows. expandcollapse popup#region - Program_name install script - (Automated with WinExists functions) #include 'Common_Functions.au3' Opt('WinTitleMatchMode', 4) Opt('TrayIconDebug', 1) ; Installer. $executable = 'filename.ext' ; Default group folder in startmenu. $group = '' ; Installation folder in Program Files. $directory = '' ; Allowed time for installation. $allowed = 60 * 1000 ; Run the installer. $pid = _Automated() $time = TimerInit() Do Select Case WinExists('', '') ControlClick('', '', '') Case WinExists('', '') ControlClick('', '', '') Case WinExists('', '') ControlClick('', '', '') Case WinExists('', '') ControlClick('', '', '') Case WinExists('', '') ControlClick('', '', '') Case Else Sleep(250) EndSelect Sleep(10) If TimerDiff($time) > $allowed Then _Abort() Until Not ProcessExists($pid) ; Remove shortcuts. If _Programs('?.lnk') Then ; Relative to programs directory ; Remove Startmenu shortcuts FileDelete('?.lnk') FileDelete('?.lnk') FileDelete('?.lnk') FileDelete('?.lnk') FileDelete('?.lnk') EndIf _Desktop('?.lnk') _QuickLaunch('?.lnk') Exit #endregion Func _Automated($parameters = Default) ; Run the installer in Default Script directory. Dim $executable If $parameters = Default Then $parameters = '' If Not FileExists($executable) And Not FileExists(@ScriptDir & '\' & $executable) Then Exit 1 ElseIf Not FileExists($executable) Then FileChangeDir(@ScriptDir) EndIf If StringRight($executable, 4) = '.msi' Then Return Run('"' & @SystemDir & '\msiexec.exe" /i "' & @WorkingDir & '\' & $executable & '" ' & $parameters) Else Return Run('"' & @WorkingDir & '\' & $executable & '" ' & $parameters) EndIf Return 0 EndFunc Func _Abort() ; close process if exists then exit. Dim $pid If ProcessExists($pid) Then ProcessClose($pid) Exit 2 Else Exit 3 EndIf EndFunc All the intelligent code handling is hidden away in functions and the main body of the script is kept simple. This helps to keep creation and maintenance hopefully to a minimum. Just add the strings copied from Au3Info and then test. (This template is perhaps a little different to the release version as I have updated a little since then). Very nice.. I like the way you have tucked this tid bit away in a function, and made it so its all handled so cleanly. You mentioned that you have a cleaner released version? How could i get my hands on that one? What is SendToA3X? I am unfamiliar with this program? Thanks Thawee Edited April 14, 2010 by thawee Link to comment Share on other sites More sharing options...
MHz Posted April 14, 2010 Share Posted April 14, 2010 Very nice.. I like the way you have tucked this tid bit away in a function, and made it so its all handled so cleanly.You mentioned that you have a cleaner released version?How could i get my hands on that one?What is SendToA3X? I am unfamiliar with this program?Thanks. Many functions are #included in the unreleased version which is good for sharing code but is hidden from view which I am not sure if evryone would like or understand well. Use the release version until I am confident to release another.The released version is on the link above given for SendToA3X. An AutoIt topic is here. You can download from 4shared here.The release version may need some updating so that may happen as soon as time allows. No promises when updating may happen. My time towards developing the project has been almost nonexistent of late. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now