Jump to content

Script Error? MouseClick takes place before Send functions (even though Send is earlier in the script)


Recommended Posts

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

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 by TheXman
Link to comment
Share on other sites

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...