RyanO Posted June 8, 2018 Share Posted June 8, 2018 I have written a script which populates fields in a window named "Setup", the final send("{ENTER}") command presses a 'Commit' button on the setup window and after a few seconds two additional windows "Confirmation" and "Audit" appear. The original setup window remains active after the 'Commit' button is pressed so I first wait for the confirmation window to appear then make it active. Unfortunately, the 'OK' button within the confirmation screen cannot be identified as a control (by the AutoIt v3 Window Info App) so I instead use the MouseClick function to identify (and click on) the location within the activated confirmation screen where the 'Ok' is situated. This appears to run correctly the first time the script is run. If however I rerun the script a second time, the mouse cursor initially selects the Setup window but then moves across the screen to where the 'Ok' button would be (before the confirmation screen is created). The script then continues sending data into the fields in the Setup window before finally hitting Commit. When the confirmation screen does appear nothing happens (I assume because the MouseClick command has already run). The code I am using is below, could someone please explain to me why the mouseclick appears to run out of sequence the second time I run the script (do I need to clear some cache somehow)? Do you need any further information to help diagnose? ; Use Window based coords rather than Screen based AutoItSetOption("MouseCoordMode",0) If WinActivate("Setup") Then ;select the first field in setup screen MouseClick("left", 60, 100) send ("95") send ("{TAB}") send ("16") send ("{TAB}") send ("1") send ("{ENTER}") ;Commit Else MsgBox($MB_SYSTEMMODAL, "", "Unable to activate setup window") EndIf WinWait("Confirmation") If not WinActive("Confirmation") Then WinActivate("Confirmation") ;select 'Ok' button MouseClick("left", 480, 235) Else MsgBox($MB_SYSTEMMODAL, "", "Unable to confirm") EndIf Link to comment Share on other sites More sharing options...
TheXman Posted June 8, 2018 Share Posted June 8, 2018 (edited) Do you really want to continue to the confirmation code even if the WinActivate("Setup") fails? Usually when an error occurs, you want to stop processing or skip any dependent code. So maybe exit after your msgbox like below. ; Use Window based coords rather than Screen based AutoItSetOption("MouseCoordMode",0) If WinActivate("Setup") Then ;select the first field in setup screen MouseClick("left", 60, 100) send ("95") send ("{TAB}") send ("16") send ("{TAB}") send ("1") send ("{ENTER}") ;Commit Else MsgBox($MB_SYSTEMMODAL, "", "Unable to activate setup window") Exit EndIf WinWait("Confirmation") If not WinActive("Confirmation") Then WinActivate("Confirmation") ;select 'Ok' button MouseClick("left", 480, 235) Else MsgBox($MB_SYSTEMMODAL, "", "Unable to confirm") Exit EndIf Edited June 8, 2018 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
SkysLastChance Posted June 8, 2018 Share Posted June 8, 2018 Maybe something like this? If WinActivate("Setup") Then ;select the first field in setup screen MouseClick("left", 60, 100) send ("95") send ("{TAB}") send ("16") send ("{TAB}") send ("1") send ("{ENTER}") ;Commit Else MsgBox($MB_SYSTEMMODAL, "", "Unable to activate setup window") Exit EndIf IF WinWaitActive ("Confirmation","",3) <> 0 Then MouseClick("left", 480, 235) Else MsgBox($MB_SYSTEMMODAL, "", "Unable to confirm") Exit EndIF You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott 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