maxix Posted September 29, 2022 Share Posted September 29, 2022 Hi, I have an application that creates multiple dialog boxes, depending on which file is being opened. In the majority of cases, the dialog box title is the same, but not always. I would like to automatically click specific buttons, depending on which dialog box appeared. I have created a partial solution, which consists of 4 different files. One example: ControlFocus("Foo","Static Text 1", "Static2") ControlClick("Foo,"&Yes","Button1") I basically have the same code in three mode files, with just the static text and buttons updated. Individually, they work fine. What I tried to do next is to have them permanently check if a dialog box comes up, since the application is started automatically through another program. Therefore, I extended each of my scripts like this: While 1 If WinExists("Foo") Then ControlFocus("Foo","Static Text 1", "Static2") ControlClick("Foo,"&Yes","Button1") EndIf WEnd The issue that I have now is that there is basically a race condition between them. Since some dialog boxes have the same title ("Foo"), whichever of my scripts finds it first will execute, which is not always the correct one for it's respective purpose. I would like to improve this and have two questions: How to check not only if a dialog box with a specific title exists, but also the text it contains (e.g., the Static2 or Static1 label text that it contains), so that I can trigger the correct action? I tried to search for a suitable function in https://www.autoitscript.com/autoit3/docs/functions.htm, but couldn't identify one that seemed appropriate to me. How to best combine all files in a single file? This should be easy once I know how to solve 1) Any help would be much appreciated! Link to comment Share on other sites More sharing options...
rsn Posted October 3, 2022 Share Posted October 3, 2022 I had done something similar with a credential filler with VNC and Cisco VPN. What I did first was get a list of windows into an array: $aWindows = WinList("[REGEXPTITLE:(?i)(.*foo.*)]") Then search the array for the specific text of the window: _ArraySearch($aWindows, "text to find", 0, 0, 0, 2) Set up some if statements and you should be able to catch any conditions you want. Link to comment Share on other sites More sharing options...
maxix Posted October 9, 2022 Author Share Posted October 9, 2022 Thank you, that's a good idea. I will see if I can get it working that way. Link to comment Share on other sites More sharing options...
maxix Posted November 19, 2022 Author Share Posted November 19, 2022 I am still having difficulties in getting it working. My current code is like this: #include <Array.au3> While 1 If WinExists("Test Program") Then $aWindows = WinList("[REGEXPTITLE:(?i)(.*Program*)]") If (_ArraySearch($aWindows, "Partial String 11", 0, 0, 0, 2)) Then ControlClick("Partial String 11","&Yes","Button1") ElseIf (_ArraySearch($aWindows, "Partial String 22", 0, 0, 0, 2)) Then ControlClick("Partial String 22","&No","Button2") ElseIf (_ArraySearch($aWindows, "Partial String 33", 0, 0, 0, 2)) Then ControlClick("Partial String 33","&OK","Button1") EndIf EndIf WEnd I've also tried to put the complete string, not just partial strings, but that didn't help either. Any suggestions on how to implement it correctly? Link to comment Share on other sites More sharing options...
rsn Posted November 22, 2022 Share Posted November 22, 2022 Looks like your: ControlClick("Partial String 11","&Yes","Button1") is missing the first argument. Should be title/hWnd/class of the window then the text. After "Partial String 11", the next arg should be the ControlID versus the text of the button. Then there's the optional arg of which button on the mouse is clicking ("left", "right", "middle", "main", "menu", "primary", "secondary". Default is the left button.) So it should look more like this: ControlClick ( "title", "text", controlID ) Assuming you'll be left clicking. I'd try something more like this (not tested since I don't know the actual strings you're searching for nor the button classes/instances of the controls): While 1 Sleep ( 200 ) $aWindows = WinList ( "[REGEXPTITLE:(?i)(.*Program.*)]" ) _ArrayAdd ( $aWindows , 0 ) $iIndex = _ArraySearch ( $aWindows , "Test Program" , Default , Default , 0 , 1 ) if @error then ContinueLoop $hWnd = WinGetHandle ( $aWindows[$index][1] ) if not @error Then MsgBox ( 0 , $index , $hWnd ) ExitLoop EndIf WEnd if $hWnd <> Null Then if WinExists ( $hWnd , "Partial String 11" ) then ControlClick($hWnd , "Partial String 11" , "[CLASS:Button; INSTANCE:1]") EndIf if WinExists ( $hWnd , "Partial String 22" ) then ControlClick($hWnd , "Partial String 22" , "[CLASS:Button; INSTANCE:1]") EndIf EndIf maxix 1 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