RadicalKoncepts Posted May 17, 2019 Share Posted May 17, 2019 I am using UIAutomation in AutoIT to autoamate a windows forms. At a particular form, I see repeated checkbox with Y and N as options as groups and interestingly I find all have the same Name, AutomationId, Text (Y/N). I am using Inspect to identify control definition and properties on these controls, but with no success! I need help to learn on possible techniques that are available to iterate/loop through these groups of check box(es) and uniquely click on them. Please Note - I am able to use sendkey command for the first Checkbox in a group. By the time, I try to access next checkbox in another group, I was not able to succeed. May I get some help here please. Link to comment Share on other sites More sharing options...
Exit Posted May 17, 2019 Share Posted May 17, 2019 And why do not we see the URL and the created code? Help us so we can help you. App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
RadicalKoncepts Posted May 17, 2019 Author Share Posted May 17, 2019 Its a windows application and I tried using simplespy. It did generate code without much luck. I tried to put those code within and it was pointed to wrong checkbox. I am going blank without ideas at the moment. Link to comment Share on other sites More sharing options...
Exit Posted May 17, 2019 Share Posted May 17, 2019 Use Au3Info and look for Classname and instance App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
junkew Posted May 19, 2019 Share Posted May 19, 2019 (edited) Uiawrappers also have index, instance and indexrelative. So if simplespy highlights the object you just have to tweak description to identify object. Make sure to use latest version from uiawrappers. Edited May 19, 2019 by junkew Earthshine and RadicalKoncepts 1 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
RadicalKoncepts Posted May 20, 2019 Author Share Posted May 20, 2019 I tried using instance sequence number. However, the automation breaks - I mean I have compiled it to an .exe and tested. Is there a try..catch block kind of stuffs that I can use to identify where and why things goes wrong? In my case, I have almost 15 Y/N option where an end user has to provide their responses. As and when I tried to setfocus/highlight/click, the .exe crashes! I am trying to learn while experimenting..not an good option though. May I get help here please? Link to comment Share on other sites More sharing options...
RadicalKoncepts Posted May 20, 2019 Author Share Posted May 20, 2019 I used index, instance. No much help to succeed. Is there a way to iterate controls that are available in TableLayoutpanel and perform click operation based on Text identification? Please help. Link to comment Share on other sites More sharing options...
RadicalKoncepts Posted May 21, 2019 Author Share Posted May 21, 2019 No luck. Is there a pseudo code or example that I can see or understand traversing or walking through controls in a panel or controls that has same id? I am trying to learn while experimenting!! Can I take help here? Link to comment Share on other sites More sharing options...
junkew Posted May 21, 2019 Share Posted May 21, 2019 Try the concept of index and indexrelative on calc.exe and start new thread in supportforum with example code. In iuiautomation thread you can see examples on treewalkers and uaage of indexrelative. Just search with your editor in the examples. RadicalKoncepts 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
junkew Posted May 22, 2019 Share Posted May 22, 2019 Ok full example on how to come where you want to be Start calc.exe Start Simplespy Hover on button 1 and press ctrl+w Example for a dutch W10 system ;~ *** Standard code maintainable *** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) _UIA_setVar("oP1","Title:=Rekenmachine;controltype:=UIA_WindowControlTypeId;class:=ApplicationFrameWindow") ;Rekenmachine _UIA_setVar("oP2","Title:=Rekenmachine;controltype:=UIA_WindowControlTypeId;class:=Windows.UI.Core.CoreWindow") ;Rekenmachine _UIA_setVar("oP3","Title:=;controltype:=UIA_GroupControlTypeId;class:=LandmarkTarget") ; _UIA_setVar("oP4","Title:=Numeriek toetsenbord;controltype:=UIA_GroupControlTypeId;class:=NamedContainerAutomationPeer") ;Numeriek toetsenbord ;~ $oUIElement=_UIA_getObjectByFindAll("Een.mainwindow", "title:=Een;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree) _UIA_setVar("oUIElement","Title:=Een;controltype:=UIA_ButtonControlTypeId;class:=Button") ;ControlType:=UIA_ButtonControlTypeId;classname:=Button") ;~ 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("oP3","highlight") _UIA_Action("oP3","setfocus") ;~_UIA_Action("oP4","highlight") _UIA_Action("oP4","setfocus") _UIA_action("oUIElement","highlight") ;~_UIA_action("oUIElement","click") Clean up to something like this I leave out the hierarchy of the different parents as mainly mainwindow is needed and leaf in ui hierarchy. If you observe speedissues it can help to put in additional layers of the hierarchy ;~ *** Standard code maintainable *** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) _UIA_setVar("oP1","Title:=Rekenmachine;controltype:=UIA_WindowControlTypeId;class:=ApplicationFrameWindow") ;Rekenmachine _UIA_setVar("oUIElement","Title:=Een;controltype:=UIA_ButtonControlTypeId;class:=Button") ;ControlType:=UIA_ButtonControlTypeId;classname:=Button") ;~ Actions split away from logical/technical definition above can come from configfiles _UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") _UIA_action("oUIElement","highlight") _UIA_action("oUIElement","click") And play with instance property #_UIA_setVar("oUIElement","Title:=Een;controltype:=UIA_ButtonControlTypeId;class:=Button") ;ControlType:=UIA_ButtonControlTypeId;classname:=Button") _UIA_setVar("oUIElement","controltype:=UIA_ButtonControlTypeId;instance:=1") ;ControlType:=UIA_ButtonControlTypeId;classname:=Button") And transformed to a full example (hopefully works in different languages of W10 directly) expandcollapse popupAutoItSetOption("MustDeclareVars", 1) #include "UIAWrappers.au3" Example() Func Example() Local $sp=wingetprocess("[active]") ; Run calc with the window maximized. Local $iPID = Run("calc", "", @SW_SHOWMAXIMIZED) ; Wait for the calc window to appear and be active Local $maxTry=1 while ($sp=wingetprocess("[active]")) and $maxTry <= 10 sleep(1000) $maxTry=$maxTry+1 WEnd ; Wait for 2 seconds. Sleep(2000) Local $calcTitle=wingettitle("[active]") ;~ Declaration of reference definitions could be put in UIA.CFG ;~ [calc] ;~ oP1=Title:=Rekenmachine;controltype:=UIA_WindowControlTypeId;class:=ApplicationFrameWindow ;~ oUIElement=controltype:=UIA_ButtonControlTypeId;instance:=11 ;~ But will do it for demo in coding _UIA_setVar("oP1","Title:=" & $calcTitle & ";controltype:=UIA_WindowControlTypeId;class:=ApplicationFrameWindow") ;Rekenmachine _UIA_setVar("oUIElement","controltype:=UIA_ButtonControlTypeId;instance:=11") ;ControlType:=UIA_ButtonControlTypeId;classname:=Button") ;~ Actions split away from logical/technical definition above can come from configfiles _UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") _UIA_action("oUIElement","highlight") _UIA_action("oUIElement","click") ;~ Just a bunch of buttons to highlight using instance property with dynamic description for $i=10 to 34 _UIA_action("controltype:=UIA_ButtonControlTypeId;instance:=" & $i ,"highlight") Next sleep(5000) ; Close the calc process using the PID returned by Run. ProcessClose($iPID) EndFunc ;==>Example RadicalKoncepts 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
RadicalKoncepts Posted June 7, 2019 Author Share Posted June 7, 2019 Thanks a tonne Junkew. I tried your directions with examples only today. It makes sense and works. Quick question here. The setFocus function creates a re color border rectangle on a target element. Is it possible to suppress or make it look like native windows focus kind? Link to comment Share on other sites More sharing options...
junkew Posted June 8, 2019 Share Posted June 8, 2019 There is a uia.cfg where you can set this behavior from highlighting true/false [Global] Debug=false Debug.file=false Highlight=true AutoStartSUT=false If the file does not exist it falls back to true as default you could overrule it in your coding with _UIA_setVar("Global.Highlight", False) and to be complete for the other 2 _UIA_setVar("Global.Debug", True) _UIA_setVar("Global.Debug.File", True) _UIA_setVar("Global.Highlight", True) RadicalKoncepts 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets 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