Jump to content
Sign in to follow this  
Earthshine

Fun with TreeWalkers

Recommended Posts

Earthshine
Posted (edited)
Quote

Command Prompt - "ConsoleApp3.exe - Shortcut.lnk"  
title bar
Microsoft Windows [Version 10.0.16299.402]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\root>cd Desktop

C:\Users\root\Desktop>"ConsoleApp3.exe - Shortcut.lnk" > file.txt

C:\Users\root\Desktop>"ConsoleApp3.exe - Shortcut.lnk" > file.txt

C:\Users\root\Desktop>"ConsoleApp3.exe - Shortcut.lnk" > file.txt

So, I made this console app--using TreeWalkers of course to walk the UI Tree-- that starts at the root and looks for enabled, active controls--and in piping that to a file, I got this (edited, lots of controls in that list), above. LOL, so, those commands that are stored in memory are control elements! Sweet. this UIAutomation stuff is awesome. @junkew got me into this, blame his IUIAutomation kit. So there is this OLD vb OCX that is super ornery, but his kit can manipulate it, even if it is just SendKeys, So I must build a C# wrapper of my own... LOL this stuff is so cool. I have tried TestStack.White and MANY other wrappers, they seriously suck, no support either.

I used canned Microsoft example code too for the most part. This is an extreme for me though, our modern stuff I can test easily enough, but I want my own kit to use to discover and poke around with. I like to use the IUIAutomation tool as a sanity check too, it's very useful.

 

Edited by Earthshine
  • Haha 1

My resources are limited. You must ask the right questions

 

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • souldjer777
      By souldjer777
      Good Morning,
      I'm trying to use the code I had previously to select an item from a list. I believe I want to "setfocus". However, I'm getting and error and I believe it's my code. I don't know what Global Variables I should be using really - and I'm not sure if "setfocus" is the right function there at the bottom of my code... Thank you all as always!!!
      Local $hWindow = WinGetHandle("My Application") ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation) If Not IsObj($oUIAutomation) Then Return ConsoleWrite("UI Automation object ERR" & @CRLF) ConsoleWrite("UI Automation object OK" & @CRLF) ; Get UI Automation element from window handle Local $pWindow, $oWindow $oUIAutomation.ElementFromHandle($hWindow, $pWindow) $oWindow = ObjCreateInterface($pWindow, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oWindow) Then Return ConsoleWrite("Automation element from window ERR" & @CRLF) ConsoleWrite("Automation element from window OK" & @CRLF) ; Condition to find text "C:\Program Files (x86)" UIA_ListItemControlTypeId Local $pCondition, $pCondition1, $pCondition2 $oUIAutomation.CreatePropertyCondition($UIA_ControlTypePropertyId, $UIA_ListItemControlTypeId, $pCondition1) $oUIAutomation.CreatePropertyCondition($UIA_NamePropertyId, "C:\Program Files (x86)", $pCondition2) $oUIAutomation.CreateAndCondition($pCondition1, $pCondition2, $pCondition) If Not $pCondition Then Return ConsoleWrite("C:\Program Files (x86) condition ERR" & @CRLF) ConsoleWrite("C:\Program Files (x86) condition OK" & @CRLF) ; Find "C:\Program Files (x86)" List Item Local $pListItem, $oListItem $oWindow.FindFirst($TreeScope_Descendants, $pCondition, $pListItem) $oListItem = ObjCreateInterface($pListItem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oListItem) Then MsgBox(0, "", "Found List Item ERR") MsgBox(0, "", "Found List Item OK") ; Focus "C:\Program Files (x86)" ListItem Local $pFocus, $oFocus $oListItem.GetCurrentPattern($UIA_ListItemControlTypeId, $pFocus) $oFocus = ObjCreateInterface($pFocus, $sIID_IUIAutomationFocusChangedEventHandler, $dtagIUIAutomationFocusChangedEventHandler) If Not IsObj($oFocus) Then MsgBox(0, "", "Focus List Item ERR") MsgBox(0, "", "Focus List Item OK") $oFocus.setfocus() Sleep(2000) FYI - I was trying the "invoke" method and the list item was actually being double clicked on - which wont work - doing invoke would bring up a new window and all I wanted to do was select the item from the list.
    • scintilla4evr
      By scintilla4evr
      Okay, this is exciting.
      I'm proud to introduce CompileIt - an experimental compiler, that allows to compile AutoIt to machine code.
      ...Kind of. CompileIt does compilation in a similar way the Glasgow Haskell compiler does: translates the code into a lower-level language (in CompileIt's case it's C), and then compiles the code in that language.
      Now, this project is still in its infancy, since, although it is simple to use, AutoIt is incredibly complex on the inside (automation, COM, etc.). So, CompileIt can compile only a very small subset of what we know as AutoIt.
      Here's a list of things CompileIt (partially) supports (or not):
      Numbers, booleans, strings Some built-in functions If, For and While statements Exporting DLL functions (you can now write DLL's in AutoIt, guys!) No arrays, automation, GUI or COM. A more detailed list is included with CompileIt.
      CompileIt is written in AutoIt (the compiler interface), JavaScript (parser, executed with ChakraCore), and of course C.
      GCC is required to compile scripts. After you extract the files, run CompileIt.exe and configure it to work with GCC.
    • scintilla4evr
      By scintilla4evr
      This is an experimental AutoIt-to-machine code compiler, written in AutoIt, JavaScript and C.
      Make sure you have GCC installed and configured within CompileIt before using.
    • bobmcrae
      By bobmcrae
      I am experimenting with UIAWrappers.au3 from junkew to complete an application which presents absolutely no control information using AutoIT Window Info.  While I am able to complete the form successfully, I am not happy with the speed.  As a benchmark, the simple Send method occurs in far less than 1-second, but the UIAutomation approach takes 3-seconds.  I am wondering whether performance gains may be achieved by specifying the controls more precisely; but I am unsure how to do that.  I was able to speed things up a bit by setting $UIA_DefaultWaitTime=0.  The controls of interest are 5-levels deep, as show in the simplespy output below.  It seems I do get faster response by specifying the target/top-level window, as show in the code below.  Any ideas?
      #include "UIAWrappers.au3" _UIA_setVar("Global.Debug", False) _UIA_setVar("Global.Debug.File", False) _UIA_setVar("Global.Highlight", False) _UIA_setVar("DPN","Title:=NC-stat DPNCheck Communicator;controltype:=UIA_WindowControlTypeId;class:=Window") _UIA_action('DPN','setFocus') _UIA_setVar("DPN.firstName","AutomationId:=txtFirstName") _UIA_setVar("DPN.lastName", "AutomationId:=txtLastName") _UIA_Action('DPN.lastName','setvalue','last name') _UIA_setVar("DPN.ID", "AutomationId:=txtSubjectId") _UIA_setVar("DPN.DOB", "AutomationId:=PART_TextBox") _UIA_setVar("DPN.Ft", "AutomationId:=txtSubjectHeight") _UIA_setVar("DPN.In", "AutomationId:=txtSubjectHeight2") _UIA_Action('DPN.firstName','setvalue','first name') _UIA_Action('DPN.ID','setvalue','ID012345') _UIA_Action('DPN.DOB','setvalue','1/31/1932') _UIA_Action('DPN.Ft','setvalue','6') _UIA_Action('DPN.In','setvalue','1') SimpleSpy output:
      ;~ *** Standard code *** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) Local $oP4=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=NC-stat DPNCheck Communicator;controltype:=UIA_WindowControlTypeId;class:=Window", $treescope_children) _UIA_Action($oP4,"setfocus") Local $oP3=_UIA_getObjectByFindAll($oP4, "Title:=;controltype:=UIA_PaneControlTypeId;class:=Frame", $treescope_children) Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=;controltype:=UIA_TabControlTypeId;class:=TabControl", $treescope_children) Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=Patient;controltype:=UIA_TabItemControlTypeId;class:=TabItem", $treescope_children) Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=;controltype:=UIA_PaneControlTypeId;class:=Frame", $treescope_children) ;~ First find the object in the parent before you can do something ;~$oUIElement=_UIA_getObjectByFindAll(".mainwindow", "title:=;ControlType:=UIA_EditControlTypeId", $treescope_subtree) Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=;ControlType:=UIA_EditControlTypeId", $treescope_subtree) _UIA_action($oUIElement,"click")  
    • Kharizmah
      By Kharizmah
      I would like to access a list view object and then get the value for the first child.
      However, there doesn't seem to be a property value available though it shows in Inspect.
      I figured it shouldn't be too difficult to add
          ["FirstChild", $UIA_FirstChildPropertyId]_  to UIAWrappers.au3
       and then a Global Variable to  CUIAutomation2.au3. However,  I'm not sure how you figure out the Id# for this Property.
      @Junkew Can you help me figure that out?

×