Sayed Posted May 4, 2020 Posted May 4, 2020 (edited) Hi there, I'm new in AutoIt forms and using AutoIt to automate desktop application (able to automate the application normally but facing issue when I've to re-run the application twice within the same script...so need help in this please) here is the steps then followed by the issue in a brief : 1- run application . 2- do some actions (click menus,activate windows,set texts..) 3- close the application. 4- run the application again & access the same controls. 5- open the same windows again (like step 2) 6- perform some validations (by getting texts from some text boxes) 7- close the application again (and repeat 1-7 for 15 times in average ) The issue * all controls are accessible in the first run and actions done successfully on controls (for steps 1-3) BUT from the second run of the application from step-4 it's able to set focus only the main application window. Note: only unique properties used to while mapping the controls. Error that appear in the console : UIAWrappers.au3" (1673) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $x = Int($t[1] + ($t[3] / 2)) $x = Int($t[1] + (^ ERROR Simple spy code of one of the controls that has this strange issue(menubar&view menu Item): ;~ *** Standard code maintainable *** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) _UIA_setVar("oP1","Title:=XXX;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app") ;main app form xxx _UIA_setVar("oP2","Title:=menuStrip1;controltype:=UIA_MenuBarControlTypeId;class:=WindowsForms10.Window.8.app") ;menuStrip1 ;~ $oUIElement=_UIA_getObjectByFindAll("View.mainwindow", "title:=View;ControlType:=UIA_MenuItemControlTypeId", $treescope_subtree) _UIA_setVar("oUIElement","Title:=View;controltype:=UIA_MenuItemControlTypeId;class:=") ;ControlType:=UIA_MenuItemControlTypeId;classname:=") ;~ Actions split away from logical/technical definition above can come from configfiles ;~_UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") ;~_UIA_Action("oP2","highlight") _UIA_Action("oP2","setfocus") _UIA_action("oUIElement","highlight") ;~_UIA_action("oUIElement","click") Edited May 5, 2020 by Sayed
Sayed Posted May 5, 2020 Author Posted May 5, 2020 (edited) @junkew @LarsJ would you please advise Edited May 5, 2020 by Sayed
junkew Posted May 5, 2020 Posted May 5, 2020 You have to clean the global array thats used with uiasetvar function. In first run its building a caching in that array and cached elements are not valid in 2nd run FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
Sayed Posted May 12, 2020 Author Posted May 12, 2020 (edited) Thanks a lot @junkew for your reply. I tried to search the fourms about how to clear the array found the following in one of your replies before: Func UIAResetRTIVars() MsgBox("", "reset", "reset", 1) ;_ArrayDisplay($UIA_Vars) for $i=(ubound($uia_vars, 1)-1) to 0 step -1 if stringleft($uia_vars[$i][0],stringlen($cRTI_Prefix))=$cRTI_Prefix Then _ArrayDelete($UIA_Vars,$i) ;_ArrayDelete($UIA_Vars,32) EndIf next MsgBox("", "reset", "Finished", 1) EndFunc & I add it in my code and call this function at the end of the first run...seeing the msg boxs of reset,finished appear after the first run done. BUT the issue now is the execution is terminated once launch the application in the second run....any advice about this strange issue ??? - also is this mean after clearing at the end of the first run , once the second run start it will declare the variables again -as I'm declaring the variable using setvar in the beginning before doing actions -??? Edited May 12, 2020 by Sayed
junkew Posted May 14, 2020 Posted May 14, 2020 (edited) Probably its enough to comment this out in uiawrappers instead of IUAResetRTIVars. In future I will make this caching of runtime type information different anyway (if I keep it in at all) ;~ Add element to runtime information object reference If IsString($p1) Then _UIA_LOG("Storing in RTI as RTI." & $p1 & @CRLF, $UIA_Log_Wrapper) _UIA_setVar("RTI." & StringUpper($p1), $UIA_oUIElementFound) EndIf these RTI vars are more important to stay in as that determines context where to search but also these can hamper your 2nd run local $rtiElements[]= ["RTI.LASTELEMENT", "RTI.FOCUSEDELEMENT", "RTI.PARENT","RTI.FOCUSEDELEMENT", "RTI.SEARCHCONTEXT", "RTI.MAINWINDOW", "RTI.DESKTOP"] Edited May 14, 2020 by junkew FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
Sayed Posted June 2, 2020 Author Posted June 2, 2020 Thanks a lot @junkew now it's running many rounds without exiting the execution.
Rainer14 Posted January 15, 2024 Posted January 15, 2024 Hi, @Sayed can you please post your solution? I have the same problem in 2nd run and comment this out was not the solution. ;~ Add element to runtime information object reference If IsString($p1) Then _UIA_LOG("Storing in RTI as RTI." & $p1 & @CRLF, $UIA_Log_Wrapper) _UIA_setVar("RTI." & StringUpper($p1), $UIA_oUIElementFound) EndIf
junkew Posted January 15, 2024 Posted January 15, 2024 ArrayDisplay($UIA_Vars) Above can help to see what's collected in first run and can influence 2nd run. The caching in rti vars is tricky implemented and not bulletproof. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
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