FordsFinest Posted February 18, 2019 Share Posted February 18, 2019 First time posting here, so i'm sure I am going to violate some sort of rule...But I am totally new to UIAutomation and am having a heck of time completing a simple task. I need to verify the name of an item in a SysTreeView32 is a certain string. I've spent days trying every GUI_CtrlTreeView command out there with no success. I downloaded this Inspect.exe tool that was helpful in showing me there was no text for the item. The string i'm looking for WAS located under Name and Legacy Accessible Name however, but I am not sure how to check that property for a selected item. Any help would be much appreciated!! Here is a snapshot of the Window Info and the tree I am trying to access. lastly, here is the Inspect Info. Link to comment Share on other sites More sharing options...
LarsJ Posted February 18, 2019 Share Posted February 18, 2019 FordsFinest, I can help you. And I don't think you've violated any rules. You'll need to download UIASpy, run the script, place the mouse cursor over the Plant item (I assume that's the item in question), press F1, right-click in the listview in UIASpy, and copy all rows. Then add a new post and paste the rows into the post. Use the <>-button at the top as you can see when creating a new post. Then you can paste the rows as text. Then I'll see what I can do. Lars. FordsFinest 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
FordsFinest Posted February 18, 2019 Author Share Posted February 18, 2019 That's too cool. Thanks a lot for the help. I actually need to click "LAP_VOW" and eventually an item located within that as well. I created an array of all the handles under "Plant" and click everything just fine, but I'm trying to add some robustness to it by checking the name of the item as well. This way if the list is ever changed i'm not just referencing array[16]. expandcollapse popupTreeview Element TreeItem: LAP_VOW Element Properties (identification) $UIA_ControlTypePropertyId $UIA_TreeItemControlTypeId $UIA_NamePropertyId LAP_VOW Element Properties (session unique) $UIA_ProcessIdPropertyId 10724 $UIA_RuntimeIdPropertyId 42,2229772,2,164376976 Element Properties (information) $UIA_BoundingRectanglePropertyId l=-1811,t=735,w=57,h=32 $UIA_FrameworkIdPropertyId Win32 $UIA_LocalizedControlTypePropertyId tree item $UIA_ProviderDescriptionPropertyId [pid:10724,hwnd:0x0 Annotation:Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main(parent link):Microsoft: TreeView Item Proxy (unmanaged:uiautomationcore.dll)] Element Properties (has/is info) $UIA_HasKeyboardFocusPropertyId True $UIA_IsContentElementPropertyId True $UIA_IsControlElementPropertyId True $UIA_IsDataValidForFormPropertyId False $UIA_IsEnabledPropertyId True $UIA_IsKeyboardFocusablePropertyId True $UIA_IsOffscreenPropertyId False $UIA_IsPasswordPropertyId False $UIA_IsRequiredForFormPropertyId False Control Patterns (element actions) $UIA_IsExpandCollapsePatternAvailablePropertyId True $UIA_IsLegacyIAccessiblePatternAvailablePropertyId True $UIA_IsScrollItemPatternAvailablePropertyId True $UIA_IsSelectionItemPatternAvailablePropertyId True Control Pattern Properties $UIA_ExpandCollapseExpandCollapseStatePropertyId $ExpandCollapseState_Collapsed $UIA_LegacyIAccessibleChildIdPropertyId 0 $UIA_LegacyIAccessibleDefaultActionPropertyId Expand $UIA_LegacyIAccessibleDescriptionPropertyId $UIA_LegacyIAccessibleHelpPropertyId $UIA_LegacyIAccessibleKeyboardShortcutPropertyId $UIA_LegacyIAccessibleNamePropertyId LAP_VOW $UIA_LegacyIAccessibleRolePropertyId 36 = $ROLE_SYSTEM_OUTLINEITEM $UIA_LegacyIAccessibleStatePropertyId 3146758 = $STATE_SYSTEM_SELECTED+$STATE_SYSTEM_FOCUSED+$STATE_SYSTEM_COLLAPSED+$STATE_SYSTEM_FOCUSABLE+$STATE_SYSTEM_SELECTABLE $UIA_LegacyIAccessibleValuePropertyId $UIA_SelectionItemIsSelectedPropertyId True $UIA_SelectionItemSelectionContainerPropertyId Control Pattern Methods ExpandCollapse Pattern Methods Expand() Collapse() CurrentExpandCollapseState(long*) LegacyIAccessible Pattern Methods DoDefaultAction() Select(long) SetValue(wstr) GetIAccessible(idispatch*) CurrentChildId(int*) CurrentDefaultAction(bstr*) CurrentDescription(bstr*) CurrentHelp(bstr*) CurrentKeyboardShortcut(bstr*) CurrentName(bstr*) CurrentRole(uint*) CurrentState(uint*) CurrentValue(bstr*) GetCurrentSelection(ptr*) ScrollItem Pattern Methods ScrollIntoView() SelectionItem Pattern Methods Select() AddToSelection() RemoveFromSelection() CurrentIsSelected(long*) CurrentSelectionContainer(ptr*) Parents from Desktop Pane: Desktop Window: Reporting Client - Perceptron - Navigation Pane: Standard Report Tree Pane: Afx:TabWnd:400000:8:10007:10 Pane: Standard Report Tree Tree: SysTreeView32 TreeItem: Plant Parent to child index Link to comment Share on other sites More sharing options...
LarsJ Posted February 18, 2019 Share Posted February 18, 2019 It's late in Copenhagen. I will look at it and return tomorrow. But it looks nice. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
FordsFinest Posted February 18, 2019 Author Share Posted February 18, 2019 Okay, thanks! Link to comment Share on other sites More sharing options...
LarsJ Posted February 19, 2019 Share Posted February 19, 2019 Run the code in SciTE with F5: expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find "Reporting Client - Perceptron - Navigation" window --- ConsoleWrite( "--- Find ""Reporting Client - Perceptron - Navigation"" window ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Reporting Client - Perceptron - Navigation window", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition0, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find treeview --- ConsoleWrite( "--- Find treeview ---" & @CRLF ) Local $pCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "SysTreeView32", $pCondition1 ) If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) Local $pTree1, $oTree1 $oWindow1.FindFirst( $TreeScope_Descendants, $pCondition1, $pTree1 ) $oTree1 = ObjCreateInterface( $pTree1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oTree1 ) Then Return ConsoleWrite( "$oTree1 ERR" & @CRLF ) ConsoleWrite( "$oTree1 OK" & @CRLF ) ; --- Find treeview item --- ConsoleWrite( "--- Find treeview item ---" & @CRLF ) Local $pCondition2, $pCondition3, $pAndCondition3 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TreeItemControlTypeId, $pCondition2 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "LAP_VOW", $pCondition3 ) ; <<<<<<<<<<<<<<<<<<<<< $oUIAutomation.CreateAndCondition( $pCondition2, $pCondition3, $pAndCondition3 ) If Not $pAndCondition3 Then Return ConsoleWrite( "$pAndCondition3 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition3 OK" & @CRLF ) Local $pTreeItem1, $oTreeItem1 $oWindow1.FindFirst( $TreeScope_Descendants, $pAndCondition3, $pTreeItem1 ) $oTreeItem1 = ObjCreateInterface( $pTreeItem1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oTreeItem1 ) Then Return ConsoleWrite( "$oTreeItem1 ERR" & @CRLF ) ConsoleWrite( "$oTreeItem1 OK" & @CRLF ) ; --- Treeview item name --- ConsoleWrite( "--- Treeview item name ---" & @CRLF ) Local $sName1 $oTreeItem1.GetCurrentPropertyValue( $UIA_NamePropertyId, $sName1 ) ConsoleWrite( "$sName1 = " & $sName1 & @CRLF ) EndFunc The code first creates the $oUIAutomation object and finds the Desktop item. Then the top window is identified by the name and $oWindow1 is created. The Treeview control is identified through class name and $oTree1 is created. LAP_VOW treview item is identified and created using the name. Finally, the name of the treview item is printed via $UIA_NamePropertyId. Note that it's not necessary to use $UIA_LegacyIAccessibleNamePropertyId. You can use $UIA_NamePropertyId. The Plant item must be expanded as shown in the picture. If it's collapsed, it can be expanded with the Expand() method of the ExpandCollapse Pattern object, which is available. It's also possible to read the names of all treeview items under Plant if you need it. Add a new post if the code doesn't work or if you have any questions. FordsFinest 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
FordsFinest Posted February 19, 2019 Author Share Posted February 19, 2019 Nice! I've ran into a couple problems though. The Reporting Client Window name will often have a different ending (e.g. Reporting Client - Perceptron - Navigation - [Navigation], etc.) The first four words stay the same, but will sometimes have something else added. I've typically used a wildcard to get around this but it didn't like it here... But, for now, I updated the name and ran it again but haven't been able to get it past the first "Find treeview" section. $oUIAutomation OK $oDesktop OK --- Find "Reporting Client - Perceptron - Navigation" window --- $pCondition0 OK $oWindow1 OK --- Find treeview --- $pCondition1 OK $oTree1 ERR I used your UIASpy tool to recreate the sample code for the tree and everything seemed to match, so I'm not sure why it's not finding the tree. expandcollapse popupTreeview Element Tree: SysTreeView32 Element Properties (identification) $UIA_ClassNamePropertyId SysTreeView32 $UIA_ControlTypePropertyId $UIA_TreeControlTypeId Element Properties (session unique) $UIA_NativeWindowHandlePropertyId 0x00000000002E09B0 $UIA_ProcessIdPropertyId 8664 $UIA_RuntimeIdPropertyId 42,3017136 Element Properties (information) $UIA_BoundingRectanglePropertyId l=-1917,t=190,w=586,h=921 $UIA_FrameworkIdPropertyId Win32 $UIA_LocalizedControlTypePropertyId tree $UIA_ProviderDescriptionPropertyId [pid:3552,hwnd:0x2E09B0 Main:Nested [pid:8664,hwnd:0x2E09B0 Annotation(parent link):Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main:Microsoft: TreeView PRoxy (unmanaged:uiautomationcore.dll)]; Nonclient:Microsoft: Non-Client Proxy (unmanaged:uiautomationcore.dll); Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)] Element Properties (has/is info) $UIA_HasKeyboardFocusPropertyId True $UIA_IsContentElementPropertyId True $UIA_IsControlElementPropertyId True $UIA_IsDataValidForFormPropertyId False $UIA_IsEnabledPropertyId True $UIA_IsKeyboardFocusablePropertyId True $UIA_IsOffscreenPropertyId False $UIA_IsPasswordPropertyId False $UIA_IsRequiredForFormPropertyId False Control Patterns (element actions) $UIA_IsLegacyIAccessiblePatternAvailablePropertyId True $UIA_IsSelectionPatternAvailablePropertyId True Control Pattern Properties $UIA_LegacyIAccessibleChildIdPropertyId 0 $UIA_LegacyIAccessibleDefaultActionPropertyId $UIA_LegacyIAccessibleDescriptionPropertyId $UIA_LegacyIAccessibleHelpPropertyId $UIA_LegacyIAccessibleKeyboardShortcutPropertyId $UIA_LegacyIAccessibleNamePropertyId $UIA_LegacyIAccessibleRolePropertyId 35 = $ROLE_SYSTEM_OUTLINE $UIA_LegacyIAccessibleStatePropertyId 1048580 = $STATE_SYSTEM_FOCUSED+$STATE_SYSTEM_FOCUSABLE $UIA_LegacyIAccessibleValuePropertyId $UIA_SelectionCanSelectMultiplePropertyId False $UIA_SelectionIsSelectionRequiredPropertyId True Control Pattern Methods LegacyIAccessible Pattern Methods DoDefaultAction() Select(long) SetValue(wstr) GetIAccessible(idispatch*) CurrentChildId(int*) CurrentDefaultAction(bstr*) CurrentDescription(bstr*) CurrentHelp(bstr*) CurrentKeyboardShortcut(bstr*) CurrentName(bstr*) CurrentRole(uint*) CurrentState(uint*) CurrentValue(bstr*) GetCurrentSelection(ptr*) Selection Pattern Methods GetCurrentSelection(ptr*) CurrentCanSelectMultiple(long*) CurrentIsSelectionRequired(long*) Parents from Desktop Pane: Desktop Window: Reporting Client - Perceptron - Navigation - [Navigation] Pane: Standard Report Tree Pane: Afx:TabWnd:400000:8:10007:10 Pane: Standard Report Tree Parent to child index Link to comment Share on other sites More sharing options...
LarsJ Posted February 19, 2019 Share Posted February 19, 2019 If you'll show information for the application window, we can surely find the window using the class name without using the window title. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
FordsFinest Posted February 19, 2019 Author Share Posted February 19, 2019 Good idea, see below. And for accessing the treeview, do I need to access each of it's parents first? It looks like it's buried within 3 parent panes. expandcollapse popupTreeview Element Window: Reporting Client - Perceptron - [Navigation] Element Properties (identification) $UIA_ClassNamePropertyId Afx:00400000:8:00010007:00000000:1F1F0EE5 $UIA_ControlTypePropertyId $UIA_WindowControlTypeId $UIA_NamePropertyId Reporting Client - Perceptron - [Navigation] Element Properties (session unique) $UIA_NativeWindowHandlePropertyId 0x0000000000720DAE $UIA_ProcessIdPropertyId 3652 $UIA_RuntimeIdPropertyId 42,7474606 Element Properties (information) $UIA_BoundingRectanglePropertyId l=-1928,t=-8,w=1936,h=1176 $UIA_FrameworkIdPropertyId Win32 $UIA_LocalizedControlTypePropertyId window $UIA_ProviderDescriptionPropertyId [pid:2640,hwnd:0x720DAE Main:Nested [pid:3652,hwnd:0x720DAE Annotation(parent link):Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main:Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll)]; Nonclient:Microsoft: Non-Client Proxy (unmanaged:uiautomationcore.dll); Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)] Element Properties (has/is info) $UIA_HasKeyboardFocusPropertyId False $UIA_IsContentElementPropertyId True $UIA_IsControlElementPropertyId True $UIA_IsDataValidForFormPropertyId False $UIA_IsEnabledPropertyId True $UIA_IsKeyboardFocusablePropertyId True $UIA_IsOffscreenPropertyId False $UIA_IsPasswordPropertyId False $UIA_IsRequiredForFormPropertyId False Control Patterns (element actions) $UIA_IsLegacyIAccessiblePatternAvailablePropertyId True $UIA_IsTransformPatternAvailablePropertyId True $UIA_IsWindowPatternAvailablePropertyId True Control Pattern Properties $UIA_LegacyIAccessibleChildIdPropertyId 0 $UIA_LegacyIAccessibleDefaultActionPropertyId $UIA_LegacyIAccessibleDescriptionPropertyId $UIA_LegacyIAccessibleHelpPropertyId $UIA_LegacyIAccessibleKeyboardShortcutPropertyId $UIA_LegacyIAccessibleNamePropertyId Reporting Client - Perceptron - [Navigation] $UIA_LegacyIAccessibleRolePropertyId 10 = $ROLE_SYSTEM_CLIENT $UIA_LegacyIAccessibleStatePropertyId 1048576 = $STATE_SYSTEM_FOCUSABLE $UIA_LegacyIAccessibleValuePropertyId $UIA_TransformCanMovePropertyId False $UIA_TransformCanResizePropertyId False $UIA_TransformCanRotatePropertyId False $UIA_WindowCanMaximizePropertyId True $UIA_WindowCanMinimizePropertyId True $UIA_WindowIsModalPropertyId False $UIA_WindowIsTopmostPropertyId False $UIA_WindowWindowInteractionStatePropertyId $WindowInteractionState_ReadyForUserInteraction $UIA_WindowWindowVisualStatePropertyId $WindowVisualState_Maximized Control Pattern Methods LegacyIAccessible Pattern Methods DoDefaultAction() Select(long) SetValue(wstr) GetIAccessible(idispatch*) CurrentChildId(int*) CurrentDefaultAction(bstr*) CurrentDescription(bstr*) CurrentHelp(bstr*) CurrentKeyboardShortcut(bstr*) CurrentName(bstr*) CurrentRole(uint*) CurrentState(uint*) CurrentValue(bstr*) GetCurrentSelection(ptr*) Transform Pattern Methods Move(double,double) Resize(double,double) Rotate(ushort) CurrentCanMove(long*) CurrentCanResize(long*) CurrentCanRotate(long*) Window Pattern Methods Close() SetWindowVisualState(long) WaitForInputIdle(int,long*) CurrentCanMaximize(long*) CurrentCanMinimize(long*) CurrentIsModal(long*) CurrentIsTopmost(long*) CurrentWindowVisualState(long*) CurrentWindowInteractionState(long*) Parents from Desktop Pane: Desktop Parent to child index Link to comment Share on other sites More sharing options...
FordsFinest Posted February 19, 2019 Author Share Posted February 19, 2019 Ah. Found a work around for the title issue since class name kept changing too. I used WinGetTitle("[ACTIVE]"). Now that just leaves me with the tree issue. I've tried activating the window prior to looking for the tree, as well as looking for the parents of the tree first but no success... $oUIAutomation OK $oDesktop OK --- Find "Reporting Client - Perceptron - Navigation" window --- $pCondition0 OK $oWindow1 OK --- Find treeview --- $pCondition1 OK $oTree1 ERR Link to comment Share on other sites More sharing options...
LarsJ Posted February 19, 2019 Share Posted February 19, 2019 Have you clicked a treeview item as you did in the picture in first post? FordsFinest 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
FordsFinest Posted February 19, 2019 Author Share Posted February 19, 2019 Ahah! I changed it from using $UIA_NamePropertyId to $UIA_ClassNamePropertyId when finding the "Reporting Client" Window and it worked! Thanks again for the help and a good into to UIA. LarsJ 1 Link to comment Share on other sites More sharing options...
FordsFinest Posted February 19, 2019 Author Share Posted February 19, 2019 Hey @LarsJ, let me know if I should create a new thread, but this still kind of falls under this post... Is it possible to read all the names of the children under Plant into an array? Then do the same thing with LAP_VOW.. I've had more success using standard action buttons. The software hasn't been consistent when using UIA. Since UIA is still the only way I know to read the names of the items in the tree view, I was hoping to make an array of them and then use a For loop to look through the array and click an item with standard action buttons. Link to comment Share on other sites More sharing options...
LarsJ Posted February 20, 2019 Share Posted February 20, 2019 (edited) I think it's fine to continue this thread. I'm not quite sure if you can blame the UIA-code for the inconsistency, though it may be convenient. You can load all Plant childs into an array ($aChilds) this way: expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find "Reporting Client - Perceptron - Navigation" window --- ConsoleWrite( "--- Find ""Reporting Client - Perceptron - Navigation"" window ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Reporting Client - Perceptron - Navigation window", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition0, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find treeview --- ConsoleWrite( "--- Find treeview ---" & @CRLF ) Local $pCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "SysTreeView32", $pCondition1 ) If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) Local $pTree1, $oTree1 $oWindow1.FindFirst( $TreeScope_Descendants, $pCondition1, $pTree1 ) $oTree1 = ObjCreateInterface( $pTree1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oTree1 ) Then Return ConsoleWrite( "$oTree1 ERR" & @CRLF ) ConsoleWrite( "$oTree1 OK" & @CRLF ) ; --- Find Plant item --- ConsoleWrite( "--- Find Plant item ---" & @CRLF ) Local $pCondition2, $pCondition3, $pAndCondition3 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TreeItemControlTypeId, $pCondition2 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Plant", $pCondition3 ) ; <<<<<<<<<<<<<<<<<<<<< $oUIAutomation.CreateAndCondition( $pCondition2, $pCondition3, $pAndCondition3 ) If Not $pAndCondition3 Then Return ConsoleWrite( "$pAndCondition3 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition3 OK" & @CRLF ) Local $pPlantItem, $oPlantItem $oTree1.FindFirst( $TreeScope_Descendants, $pAndCondition3, $pPlantItem ) $oPlantItem = ObjCreateInterface( $pPlantItem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oPlantItem ) Then Return ConsoleWrite( "$oPlantItem ERR" & @CRLF ) ConsoleWrite( "$oPlantItem OK" & @CRLF ) ; --- Plant childs --- ConsoleWrite( "--- Plant childs ---" & @CRLF ) Local $pCondition4 $oUIAutomation.CreateTrueCondition( $pCondition4 ) If Not $pCondition4 Then Return ConsoleWrite( "$pCondition4 ERR" & @CRLF ) ConsoleWrite( "$pCondition4 OK" & @CRLF ) Local $pChilds $oPlantItem.FindAll( $TreeScope_Children, $pCondition4, $pChilds ) ; Childs only If Not $pChilds Then Return ConsoleWrite( "$pChilds ERR" & @CRLF ) ConsoleWrite( "$pChilds OK" & @CRLF ) Local $oAutomationElementArray, $iChilds $oAutomationElementArray = ObjCreateInterFace( $pChilds, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray ) $oAutomationElementArray.Length( $iChilds ) If Not $iChilds Then Return ConsoleWrite( "$iChilds ERR" & @CRLF ) ConsoleWrite( "$iChilds = " & $iChilds & @CRLF ) ConsoleWrite( "$iChilds OK" & @CRLF ) Local $pTVitem, $oTVitem Local $aChilds[$iChilds] For $i = 0 To $iChilds - 1 $oAutomationElementArray.GetElement( $i, $pTVitem ) $oTVitem = ObjCreateInterface( $pTVitem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) $oTVitem.GetCurrentPropertyValue( $UIA_NamePropertyId, $aChilds[$i] ) ConsoleWrite( "Child" & $i & " = " & $aChilds[$i] & @CRLF ) Next EndFunc I made a mistake in the previous code: ; --- Find treeview item --- ConsoleWrite( "--- Find treeview item ---" & @CRLF ) Local $pCondition2, $pCondition3, $pAndCondition3 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TreeItemControlTypeId, $pCondition2 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "LAP_VOW", $pCondition3 ) ; <<<<<<<<<<<<<<<<<<<<< $oUIAutomation.CreateAndCondition( $pCondition2, $pCondition3, $pAndCondition3 ) If Not $pAndCondition3 Then Return ConsoleWrite( "$pAndCondition3 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition3 OK" & @CRLF ) Local $pTreeItem1, $oTreeItem1 $oWindow1.FindFirst( $TreeScope_Descendants, $pAndCondition3, $pTreeItem1 ) $oTreeItem1 = ObjCreateInterface( $pTreeItem1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oTreeItem1 ) Then Return ConsoleWrite( "$oTreeItem1 ERR" & @CRLF ) ConsoleWrite( "$oTreeItem1 OK" & @CRLF ) Replace $oWindow1 with $oTree1. I don't think the error has had any consequences. You got the right result anyway. Edited February 20, 2019 by LarsJ FordsFinest 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
FordsFinest Posted February 20, 2019 Author Share Posted February 20, 2019 Man...I can't express my gratitude enough. It worked great! I used StringInStr to check the items in the array and then _GUICtrlTreeView_ClickItem... I'm not sure why I was having the previous trouble. I used UIA to select an item, but once I invoked a button to "Set Sample Size", it brought up a menu for the wrong tree item. Everything in the UIASpy said it the correct tree item was selected, focused, etc, matching exactly as if I had clicked the tree item with my own mouse. But still the issue was occurring. But this works great and i'll be using it for many other things now too! LarsJ 1 Link to comment Share on other sites More sharing options...
LarsJ Posted February 20, 2019 Share Posted February 20, 2019 You're welcome. There will be a major update of UIASpy in the weekend. The new version is much better than the old one. Don't miss it. FordsFinest 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions 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