Search the Community
Showing results for tags 'uiautomation'.
-
I'm trying to understand the use of TreeWalker and DllCall()s. My ultimate goal is to use TreeWalker to list all children of webpages. I've been working through the files for UIASpy to understand the logic. After a weeks worth of searching for examples I'm still stuck on the reason for the repeated use of DllCalls in most of the functions. Here is an example - the function 'UIASpy_CheckWindows()' (located in UIASpy_Elements.au3) is called from file UIASpy_Gui.au3. In the function the following DllCall is used: DllCall( "user32.dll", "lresult", "SendMessageW", "hwnd", $hTV, "uint", $TVM_GETITEMW, "wparam", 0, "struct*", $tItem ) I understand that the function 'SendMessageW' in 'user32.dll' sends a message to the window $hTV. The message is '$TVM_GETNEXTITEM' and '$tItem' is a struct with additional information - Microsoft Doc -https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessagew. The window $hTV is created in UIASpy_Gui.au3 and that's where I get lost. Is there code in UIASpy_Gui.au3 that handles this message? I don't know what to look for. This procedure - Function called that contains DllCall (SendMessage) is repeatedly used. Thanks in advance.
-
Hello, I'm trying to automate the settings of combo boxes in a program. The combo boxes are child windows of two different windows. They have the similar but different titles so I can locate them using 'WinList('ES 06-20-NT8')'. After I locate the windows I need to change the selection in a combo box on each. I initially tried to use the window handle of the respective windows to create an element for each with '$oUIAutomation.ElementFromHandle( $hWindow, $pWindow )'. The objects will create and I can read the contents of the combo boxes. When I try to change the value using .SetValue() the combo box in only one of the windows changes. WinActivate() or .SetFocus() will change the active window but the combo box will still only change in one of the windows. Next attempt is to use the '$UIA_AutomationIdPropertyId' & ' $UIA_NativeWindowHandlePropertyId to create an ''AndCondition'. I've included the script for this. The problem now is that each time the program restarts the value for '$UIA_NativeWindowHandlePropertyId ' changes. If I get the current value using UIASpy and input the values into the script it will work. I've searched every place I can think of to find out how I can get the current value for '$UIA_NativeWindowHandlePropertyId ' and automate it. Any suggestions are greatly appreciated. #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include "C:\Users\Rod\Documents\AutoIt\Include\UIA_Constants.au3" ; Can be copied from UIASpy Includes folder #include "C:\Users\Rod\Documents\AutoIt\Include\CUIAutomation2WithDuplicateConstantsRemoved.au3" #include 'Array.au3' Opt("MustDeclareVars", 1) Example() Func Example() ; creates an array with 3 rows Local $aArr = WinList('ES 06-20-NT8') _ArrayDisplay($aArr) For $i = 1 To UBound($aArr) - 1 ConsoleWrite($aArr[$i][0] & ' ' & $aArr[$i][1] & @CRLF) Next ; tried window handle for property condition in '$UIA_NativeWindowHandlePropertyId' but it doesn't work ; Local $hWnd = WinGetHandle($aArr[1][0]) ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation8, $sIID_IUIAutomation5, $dtag_IUIAutomation5) 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_IUIAutomationElement8, $dtag_IUIAutomationElement8) If Not IsObj($oDesktop) Then Return ConsoleWrite("$oDesktop ERR" & @CRLF) ConsoleWrite("$oDesktop OK" & @CRLF) ; --- Find window/control --- ConsoleWrite("--- Find window/control ---" & @CRLF) Local $pCondition0, $pCondition1, $pAndCondition1 $oUIAutomation.CreatePropertyCondition($UIA_AutomationIdPropertyId, "accountComboBox", $pCondition0) $oUIAutomation.CreatePropertyCondition($UIA_NativeWindowHandlePropertyId, 0x001506B6, $pCondition1) $oUIAutomation.CreateAndCondition($pCondition0, $pCondition1, $pAndCondition1) If Not $pAndCondition1 Then Return ConsoleWrite("$pAndCondition1 ERR" & @CRLF) ConsoleWrite("$pAndCondition1 OK" & @CRLF) Local $pComboBox1, $oComboBox1 $oDesktop.FindFirst($TreeScope_Descendants, $pAndCondition1, $pComboBox1) $oComboBox1 = ObjCreateInterface($pComboBox1, $sIID_IUIAutomationElement8, $dtag_IUIAutomationElement8) If Not IsObj($oComboBox1) Then Return ConsoleWrite("$oComboBox1 ERR" & @CRLF) ConsoleWrite("$oComboBox1 OK" & @CRLF) ; --- LegacyIAccessible Pattern (action) Object --- ConsoleWrite("--- LegacyIAccessible Pattern (action) Object ---" & @CRLF) Local $pLegacyIAccessiblePattern1, $oLegacyIAccessiblePattern1 $oComboBox1.GetCurrentPattern($UIA_LegacyIAccessiblePatternId, $pLegacyIAccessiblePattern1) $oLegacyIAccessiblePattern1 = ObjCreateInterface($pLegacyIAccessiblePattern1, $sIID_IUIAutomationLegacyIAccessiblePattern, $dtag_IUIAutomationLegacyIAccessiblePattern) If Not IsObj($oLegacyIAccessiblePattern1) Then Return ConsoleWrite("$oLegacyIAccessiblePattern1 ERR" & @CRLF) ConsoleWrite("$oLegacyIAccessiblePattern1 OK" & @CRLF) ; --- LegacyIAccessible Pattern (action) Methods --- ConsoleWrite("--- LegacyIAccessible Pattern (action) Methods ---" & @CRLF) Local $sValue $oLegacyIAccessiblePattern1.CurrentValue($sValue) ConsoleWrite("$oLegacyIAccessiblePattern1.CurrentValue() = " & $sValue & @CRLF) ; --- Value Pattern (action) Object --- ConsoleWrite("--- Value Pattern (action) Object ---" & @CRLF) Local $pValuePattern1, $oValuePattern1 $oComboBox1.GetCurrentPattern($UIA_ValuePatternId, $pValuePattern1) $oValuePattern1 = ObjCreateInterface($pValuePattern1, $sIID_IUIAutomationValuePattern, $dtag_IUIAutomationValuePattern) If Not IsObj($oValuePattern1) Then Return ConsoleWrite("$oValuePattern1 ERR" & @CRLF) ConsoleWrite("$oValuePattern1 OK" & @CRLF) ; --- Value Pattern (action) Methods --- ConsoleWrite("--- Value Pattern (action) Methods ---" & @CRLF) $oValuePattern1.SetValue('NT8-Sim 03 Tue') ConsoleWrite("$oValuePattern1.SetValue()" & @CRLF) $oLegacyIAccessiblePattern1.CurrentValue($sValue) ConsoleWrite("$oLegacyIAccessiblePattern1.CurrentValue() = " & $sValue & @CRLF) ; --- Find window/control --- ConsoleWrite("--- Find window/control ---" & @CRLF) ; --- Find window/control --- ConsoleWrite("--- Find window/control ---" & @CRLF) $oUIAutomation.CreatePropertyCondition($UIA_AutomationIdPropertyId, "accountComboBox", $pCondition0) $oUIAutomation.CreatePropertyCondition($UIA_NativeWindowHandlePropertyId, 0x0010069E, $pCondition1) $oUIAutomation.CreateAndCondition($pCondition0, $pCondition1, $pAndCondition1) If Not $pAndCondition1 Then Return ConsoleWrite("$pAndCondition1 ERR" & @CRLF) ConsoleWrite("$pAndCondition1 OK" & @CRLF) $oDesktop.FindFirst($TreeScope_Descendants, $pAndCondition1, $pComboBox1) $oComboBox1 = ObjCreateInterface($pComboBox1, $sIID_IUIAutomationElement8, $dtag_IUIAutomationElement8) If Not IsObj($oComboBox1) Then Return ConsoleWrite("$oComboBox1 ERR" & @CRLF) ConsoleWrite("$oComboBox1 OK" & @CRLF) ; --- LegacyIAccessible Pattern (action) Object --- ConsoleWrite("--- LegacyIAccessible Pattern (action) Object ---" & @CRLF) $oComboBox1.GetCurrentPattern($UIA_LegacyIAccessiblePatternId, $pLegacyIAccessiblePattern1) $oLegacyIAccessiblePattern1 = ObjCreateInterface($pLegacyIAccessiblePattern1, $sIID_IUIAutomationLegacyIAccessiblePattern, $dtag_IUIAutomationLegacyIAccessiblePattern) If Not IsObj($oLegacyIAccessiblePattern1) Then Return ConsoleWrite("$oLegacyIAccessiblePattern1 ERR" & @CRLF) ConsoleWrite("$oLegacyIAccessiblePattern1 OK" & @CRLF) ; --- LegacyIAccessible Pattern (action) Methods --- ConsoleWrite("--- LegacyIAccessible Pattern (action) Methods ---" & @CRLF) $oLegacyIAccessiblePattern1.CurrentValue($sValue) ConsoleWrite("$oLegacyIAccessiblePattern1.CurrentValue()" & $sValue & @CRLF) ; --- Value Pattern (action) Object --- ConsoleWrite("--- Value Pattern (action) Object ---" & @CRLF) $oComboBox1.GetCurrentPattern($UIA_ValuePatternId, $pValuePattern1) $oValuePattern1 = ObjCreateInterface($pValuePattern1, $sIID_IUIAutomationValuePattern, $dtag_IUIAutomationValuePattern) If Not IsObj($oValuePattern1) Then Return ConsoleWrite("$oValuePattern1 ERR" & @CRLF) ConsoleWrite("$oValuePattern1 OK" & @CRLF) ; --- Value Pattern (action) Methods --- ConsoleWrite("--- Value Pattern (action) Methods ---" & @CRLF) $oValuePattern1.SetValue('NT8-Sim 03 Tue') ConsoleWrite("$oValuePattern1.SetValue()" & @CRLF) $oLegacyIAccessiblePattern1.CurrentValue($sValue) ConsoleWrite("$oLegacyIAccessiblePattern1.CurrentValue() = " & $sValue & @CRLF) EndFunc ;==>Example Output from script ES 06-20-NT8-Sim 02 Mon 0x05D50AAA ES 06-20-NT8-Sim04 Wed 0x001208B8 $oUIAutomation OK $oDesktop OK --- Find window/control --- $pAndCondition1 OK $oComboBox1 OK --- LegacyIAccessible Pattern (action) Object --- $oLegacyIAccessiblePattern1 OK --- LegacyIAccessible Pattern (action) Methods --- $oLegacyIAccessiblePattern1.CurrentValue() = NT8-Sim 02 Mon --- Value Pattern (action) Object --- $oValuePattern1 OK --- Value Pattern (action) Methods --- $oValuePattern1.SetValue() $oLegacyIAccessiblePattern1.CurrentValue() = NT8-Sim 03 Tue --- Find window/control --- --- Find window/control --- $pAndCondition1 OK $oComboBox1 OK --- LegacyIAccessible Pattern (action) Object --- $oLegacyIAccessiblePattern1 OK --- LegacyIAccessible Pattern (action) Methods --- $oLegacyIAccessiblePattern1.CurrentValue()NT8-Sim04 Wed --- Value Pattern (action) Object --- $oValuePattern1 OK --- Value Pattern (action) Methods --- $oValuePattern1.SetValue() $oLegacyIAccessiblePattern1.CurrentValue() = NT8-Sim 03 Tue Thanks in advance.
-
Hello, I'm trying to set a value in a combo box on a Chrome web page. I've checked that the Chrome://accessibility is on and have checked to see that it's working with one of @LarsJ's scripts. I've been able to locate the combo box and expand it. I have then tried to put the contents into an element array. When I check to see if the array is created there is no error. When I check the size of the array with '$oUIElementArray1.Length($iLength1)' the length is zero. I then tried to set the value in the combo box with .SetValue(). No luck. Next I tried to get the combo box items with '$oSelectionPattern1.GetCurrentSelection($pElementArray*)'. My assumption is that the combo box items are put in an array - $pElementArray* though I couldn't get this to work in another program. I've included the script and output. This is my first attempt working with a website so that is likely where the problem is. I've used all of the code except '$oSelectionPattern1' successfully in another script. #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include "C:\Users\Rod\Documents\AutoIt\Include\UIA_Constants.au3" ; Can be copied from UIASpy Includes folder #include "C:\Users\Rod\Documents\AutoIt\Include\CUIAutomation2WithDuplicatesRemoved.au3" ;~ #include "C:\Users\Rod\Documents\AutoIt\Jigsaw Open Journalytix\Jigsaw Open Journalytix 01.au3" Opt("MustDeclareVars", 1) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation8, $sIID_IUIAutomation5, $dtag_IUIAutomation5) If Not IsObj($oUIAutomation) Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oUIAutomation ERR" & @CRLF) ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oUIAutomation OK" & @CRLF) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement($pDesktop) $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement8, $dtag_IUIAutomationElement8) If Not IsObj($oDesktop) Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oDesktop ERR" & @CRLF) ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oDesktop OK" & @CRLF) ; --- Find window/control --- ConsoleWrite("--- Find window/control ---" & @CRLF) ; locate browser Local $pCondition0 $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "Chrome_WidgetWin_1", $pCondition0) If Not $pCondition0 Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $pCondition0 ERR" & @CRLF) ConsoleWrite(':' & @ScriptLineNumber & ':' & " $pCondition0 OK" & @CRLF) Local $pPane1, $oPane1 $oDesktop.FindFirst($TreeScope_Descendants, $pCondition0, $pPane1) $oPane1 = ObjCreateInterface($pPane1, $sIID_IUIAutomationElement8, $dtag_IUIAutomationElement8) If Not IsObj($oPane1) Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oPane1 ERR" & @CRLF) ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oPane1 OK" & @CRLF) ; --- Find combo box --- ConsoleWrite("--- Find combo box ---" & @CRLF) Local $pCondition1 $oUIAutomation.CreatePropertyCondition($UIA_ControlTypePropertyId, $UIA_ComboBoxControlTypeId, $pCondition1) If Not $pCondition1 Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $pCondition1 ERR" & @CRLF) ConsoleWrite(':' & @ScriptLineNumber & ':' & " $pCondition1 OK" & @CRLF) Local $pComboBox1, $oComboBox1 $oPane1.FindFirst($TreeScope_Descendants, $pCondition1, $pComboBox1) $oComboBox1 = ObjCreateInterface($pComboBox1, $sIID_IUIAutomationElement8, $dtag_IUIAutomationElement8) If Not IsObj($oComboBox1) Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oComboBox1 ERR" & @CRLF) ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oComboBox1 OK" & @CRLF) ; --- ExpandCollapse Pattern (action) Object --- ConsoleWrite("--- ExpandCollapse Pattern (action) Object ---" & @CRLF) Local $pExpandCollapsePattern1, $oExpandCollapsePattern1 $oComboBox1.GetCurrentPattern($UIA_ExpandCollapsePatternId, $pExpandCollapsePattern1) $oExpandCollapsePattern1 = ObjCreateInterface($pExpandCollapsePattern1, $sIID_IUIAutomationExpandCollapsePattern, $dtag_IUIAutomationExpandCollapsePattern) If Not IsObj($oExpandCollapsePattern1) Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oExpandCollapsePattern1 ERR" & @CRLF) ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oExpandCollapsePattern1 OK" & @CRLF) ; --- ExpandCollapse Pattern (action) Methods --- ConsoleWrite("--- ExpandCollapse Pattern (action) Methods ---" & @CRLF) $oExpandCollapsePattern1.Expand() ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oExpandCollapsePattern1.Expand()" & @CRLF) Local $oUIElementArray1, $iLength1, $pElements ; $pElements is a pointer to an UI Automation element array Local $pTrueCondition $oUIAutomation.CreateTrueCondition($pTrueCondition) ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oUIAutomation.CreateTrueCondition()" & @CRLF) If Not $pTrueCondition Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $pTrueCondition ERR" & @CRLF) ConsoleWrite(':' & @ScriptLineNumber & ':' & " $pTrueCondition OK" & @CRLF) $oComboBox1.FindAll($TreeScope_Children, $pTrueCondition, $pElements) $oUIElementArray1 = ObjCreateInterface($pElements, $sIID_IUIAutomationElementArray, $dtag_IUIAutomationElementArray) If Not IsObj($oUIElementArray1) Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oUIElementArray1 ERR" & @CRLF) ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oUIElementArray1 OK" & @CRLF) ; script stops here - apparently array is not created $oUIElementArray1.Length($iLength1) If Not $iLength1 Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $iLength1 = 0 ERR" & @CRLF) ConsoleWrite(':' & @ScriptLineNumber & ':' & " $iLength1 = " & $iLength1 & @CRLF) #cs============================================================================= Display array #ce============================================================================= Local $pElement1, $oElement1, $sValue1 For $i = 0 To $iLength1 - 1 $oUIElementArray1.GetElement($i, $pElement1) $oElement1 = ObjCreateInterface($pElement1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) $oElement1.GetCurrentPropertyValue($UIA_NamePropertyId, $sValue1) ConsoleWrite(':' & @ScriptLineNumber & ':' & " $sValue" & $i & "= " & $sValue1 & @CRLF) Next ; --- LegacyIAccessible Pattern (action) Object --- ConsoleWrite("--- LegacyIAccessible Pattern (action) Object ---" & @CRLF) Local $pLegacyIAccessiblePattern1, $oLegacyIAccessiblePattern1 $oComboBox1.GetCurrentPattern($UIA_LegacyIAccessiblePatternId, $pLegacyIAccessiblePattern1) $oLegacyIAccessiblePattern1 = ObjCreateInterface($pLegacyIAccessiblePattern1, $sIID_IUIAutomationLegacyIAccessiblePattern, $dtag_IUIAutomationLegacyIAccessiblePattern) If Not IsObj($oLegacyIAccessiblePattern1) Then Return ConsoleWrite("$oLegacyIAccessiblePattern1 ERR" & @CRLF) ConsoleWrite("$oLegacyIAccessiblePattern1 OK" & @CRLF) ; --- LegacyIAccessible Pattern (action) Methods --- ; tried to set value into combobox but nothing happens ConsoleWrite("--- LegacyIAccessible Pattern (action) Methods ---" & @CRLF) Local $sShowEntriesCombobox = 'All' $oLegacyIAccessiblePattern1.SetValue($sShowEntriesCombobox) ConsoleWrite("$oLegacyIAccessiblePattern1.SetValue()" & @CRLF) ; --- Selection Pattern (action) Object --- ConsoleWrite("--- Selection Pattern (action) Object ---" & @CRLF) Local $pSelectionPattern1, $oSelectionPattern1 $oComboBox1.GetCurrentPattern($UIA_SelectionPatternId, $pSelectionPattern1) $oSelectionPattern1 = ObjCreateInterface($pSelectionPattern1, $sIID_IUIAutomationSelectionPattern, $dtag_IUIAutomationSelectionPattern) Sleep(1000) If Not IsObj($oSelectionPattern1) Then Return ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oSelectionPattern1 ERR" & @CRLF) ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oSelectionPattern1 OK" & @CRLF) ; --- Selection Pattern (action) Methods --- ConsoleWrite("--- Selection Pattern (action) Methods ---" & @CRLF) $oSelectionPattern1.GetCurrentSelection($pElements) ConsoleWrite(':' & @ScriptLineNumber & ':' & " $oSelectionPattern1.GetCurrentSelection()" & @CRLF) EndFunc ;==>Example Console Output >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\Rod\Documents\AutoIt\jigsaw Show Entries Code\JIgsa Show Entries Combobox - for Forum 02.au3" /UserParams +>15:31:00 Starting AutoIt3Wrapper v.19.102.1901.0 SciTE v.4.1.2.0 Keyboard:00000409 OS:WIN_10/ CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:2 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\Rod\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\Rod\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.5) params:-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 from:C:\Program Files (x86)\AutoIt3 input:C:\Users\Rod\Documents\AutoIt\jigsaw Show Entries Code\JIgsa Show Entries Combobox - for Forum 02.au3 +>15:31:00 AU3Check ended.rc:0 >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\Rod\Documents\AutoIt\jigsaw Show Entries Code\JIgsa Show Entries Combobox - for Forum 02.au3" +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop :18: $oUIAutomation OK :25: $oDesktop OK --- Find window/control --- :35: $pCondition0 OK :41: $oPane1 OK --- Find combo box --- :50: $pCondition1 OK :56: $oComboBox1 OK --- ExpandCollapse Pattern (action) Object --- :66: $oExpandCollapsePattern1 OK --- ExpandCollapse Pattern (action) Methods --- :73: $oExpandCollapsePattern1.Expand() :79: $oUIAutomation.CreateTrueCondition() :81: $pTrueCondition OK :88: $oUIElementArray1 OK :92: $iLength1 = 0 ERR +>15:31:00 AutoIt3.exe ended.rc:0 +>15:31:00 AutoIt3Wrapper Finished. >Exit code: 0 Time: 1.681 Thanks in advance
-
I'm trying to set the slider in a window using RangeValuePattern.SetValue(). The window is used to set the start point for replaying market data in the app NinjaTrader 8. When using the Action window in Inspect.exe I can set a value and the slider responds. When I run a script that selects the slider and uses .SetValue() with the same value the slider does not move. I've tried giving the focus to the slider with no change in results. #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 "C:\Users\Rod\Documents\AutoIt\Include\UIA_Constants.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_SafeArray.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Variant.au3" ; Can be copied from UIASpy Includes folder Opt("MustDeclareVars", 1) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation8, $sIID_IUIAutomation5, $dtag_IUIAutomation5) 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_IUIAutomationElement8, $dtag_IUIAutomationElement8) If Not IsObj($oDesktop) Then Return ConsoleWrite("$oDesktop ERR" & @CRLF) ConsoleWrite("$oDesktop OK" & @CRLF) ; --- Find window/control --- ConsoleWrite("--- Find window/control ---" & @CRLF) Local $pCondition0 $oUIAutomation.CreatePropertyCondition($UIA_NamePropertyId, "Playback", $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_IUIAutomationElement8, $dtag_IUIAutomationElement8) If Not IsObj($oWindow1) Then Return ConsoleWrite("$oWindow1 ERR" & @CRLF) ConsoleWrite("$oWindow1 OK" & @CRLF) ; --- Find window/control --- ConsoleWrite("--- Find window/control ---" & @CRLF) Local $pCondition1 $oUIAutomation.CreatePropertyCondition($UIA_AutomationIdPropertyId, "slider", $pCondition1) If Not $pCondition1 Then Return ConsoleWrite("$pCondition1 ERR" & @CRLF) ConsoleWrite("$pCondition1 OK" & @CRLF) Local $pSlider1, $oSlider1 $oWindow1.FindFirst($TreeScope_Descendants, $pCondition1, $pSlider1) $oSlider1 = ObjCreateInterface($pSlider1, $sIID_IUIAutomationElement8, $dtag_IUIAutomationElement8) If Not IsObj($oSlider1) Then Return ConsoleWrite("$oSlider1 ERR" & @CRLF) ConsoleWrite("$oSlider1 OK" & @CRLF) ; --- RangeValue Pattern (action) Object --- ConsoleWrite("--- RangeValue Pattern (action) Object ---" & @CRLF) Local $pRangeValuePattern1, $oRangeValuePattern1 $oSlider1.GetCurrentPattern($UIA_RangeValuePatternId, $pRangeValuePattern1) $oRangeValuePattern1 = ObjCreateInterface($pRangeValuePattern1, $sIID_IUIAutomationRangeValuePattern, $dtag_IUIAutomationRangeValuePattern) If Not IsObj($oRangeValuePattern1) Then Return ConsoleWrite("$oRangeValuePattern1 ERR" & @CRLF) ConsoleWrite("$oRangeValuePattern1 OK" & @CRLF) ; --- RangeValue Pattern (action) Methods --- ConsoleWrite("--- RangeValue Pattern (action) Methods ---" & @CRLF) Local $iSetValue = 50000 $oRangeValuePattern1.SetValue($iSetValue) ConsoleWrite("$oRangeValuePattern1.SetValue()" & @CRLF) EndFunc ;==>Example Console Output >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\Rod\Documents\AutoIt\NT8 PlayBack\NT8 PlayBack01.au3" /UserParams +>10:39:16 Starting AutoIt3Wrapper v.19.102.1901.0 SciTE v.4.1.2.0 Keyboard:00000409 OS:WIN_10/ CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:2 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\Rod\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\Rod\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.5) params:-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 from:C:\Program Files (x86)\AutoIt3 input:C:\Users\Rod\Documents\AutoIt\NT8 PlayBack\NT8 PlayBack01.au3 +>10:39:16 AU3Check ended.rc:0 >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Users\Rod\Documents\AutoIt\NT8 PlayBack\NT8 PlayBack01.au3" +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop $oUIAutomation OK $oDesktop OK --- Find window/control --- $pCondition0 OK $oWindow1 OK --- Find window/control --- $pCondition1 OK $oSlider1 OK --- RangeValue Pattern (action) Object --- $oRangeValuePattern1 OK --- RangeValue Pattern (action) Methods --- $oRangeValuePattern1.SetValue() +>10:39:16 AutoIt3.exe ended.rc:0 +>10:39:16 AutoIt3Wrapper Finished. >Exit code: 0 Time: 1.087 I'm a noob with autoit and tried to attach screenshots to this post. I have shots from UIASpy and Inspect.exe. When I try to attach them I get an "Upload Failed" message. They show results from the respective programs. As an alternative I included the apps results with the slider selected. Inspect.exe: How found: Selected from tree... Name: "" ControlType: UIA_SliderControlTypeId (0xC35F) LocalizedControlType: "slider" BoundingRectangle: {l:1579 t:531 r:1801 b:549} IsEnabled: true IsOffscreen: false IsKeyboardFocusable: true HasKeyboardFocus: false AcceleratorKey: "" AccessKey: "" ProcessId: 9928 RuntimeId: [7.26C8.279F814] AutomationId: "slider" FrameworkId: "WPF" ClassName: "Slider" IsControlElement: true IsContentElement: true ProviderDescription: "[pid:9928,providerId:0x0 Main(parent link):Unidentified Provider (managed:MS.Internal.Automation.ElementProxy, PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)]" IsPassword: false ItemStatus: "" ItemType: "" IsRequiredForForm: false HelpText: "" ClickablePoint: {x:-2147483648 y:-2147483648} Orientation: 0 LegacyIAccessible.ChildId: 0 LegacyIAccessible.DefaultAction: "" LegacyIAccessible.Description: "" LegacyIAccessible.Help: "" LegacyIAccessible.KeyboardShortcut: "" LegacyIAccessible.Name: "" LegacyIAccessible.Role: slider (0x33) LegacyIAccessible.State: focusable (0x100000) LegacyIAccessible.Value: "0" RangeValue.IsReadOnly: false RangeValue.LargeChange: 1.000000 RangeValue.Maximum: 691200.000000 RangeValue.Minimum: 0.000000 RangeValue.SmallChange: 0.100000 RangeValue.Value: 0.000000 IsAnnotationPatternAvailable: false IsDragPatternAvailable: false IsDockPatternAvailable: false IsDropTargetPatternAvailable: false IsExpandCollapsePatternAvailable: false IsGridItemPatternAvailable: false IsGridPatternAvailable: false IsInvokePatternAvailable: false IsItemContainerPatternAvailable: false IsLegacyIAccessiblePatternAvailable: true IsMultipleViewPatternAvailable: false IsObjectModelPatternAvailable: false IsRangeValuePatternAvailable: true IsScrollItemPatternAvailable: false IsScrollPatternAvailable: false IsSelectionItemPatternAvailable: false IsSelectionPatternAvailable: false IsSpreadsheetItemPatternAvailable: false IsSpreadsheetPatternAvailable: false IsStylesPatternAvailable: false IsSynchronizedInputPatternAvailable: true IsTableItemPatternAvailable: false IsTablePatternAvailable: false IsTextChildPatternAvailable: false IsTextEditPatternAvailable: false IsTextPatternAvailable: false IsTextPattern2Available: false IsTogglePatternAvailable: false IsTransformPatternAvailable: false IsTransform2PatternAvailable: false IsValuePatternAvailable: false IsVirtualizedItemPatternAvailable: false IsWindowPatternAvailable: false IsCustomNavigationPatternAvailable: false IsSelectionPattern2Available: false FirstChild: "" thumb LastChild: "" thumb Next: "M0,3C0,3 0,4 0,4 0,4 3,4 3,4 3,4 3,3 3,3 3,3 4,3 4,3 4,3 4,4 4,4 4,4 7,4 7,4 7,4 7,3 7,3 7,3 6,3 6,3 6,3 6,2 6,2 6,2 5,2 5,2 5, Previous: "" button Other Props: Object has no additional properties Children: "" thumb Ancestors: "Playback" window "Desktop 1" pane [ No Parent ] UIASpy: Treeview Element Slider: Slider Element Properties (identification) $UIA_AutomationIdPropertyId slider $UIA_ClassNamePropertyId Slider $UIA_ControlTypePropertyId $UIA_SliderControlTypeId Element Properties (session unique) $UIA_ProcessIdPropertyId 9928 $UIA_RuntimeIdPropertyId 7,9928,41547796 Element Properties (information) $UIA_BoundingRectanglePropertyId l=1579,t=531,w=222,h=18 $UIA_ClickablePointPropertyId -2147483648,-2147483648 $UIA_FrameworkIdPropertyId WPF $UIA_HeadingLevelPropertyId 80050 $UIA_LocalizedControlTypePropertyId slider $UIA_OptimizeForVisualContentPropertyId False $UIA_ProviderDescriptionPropertyId [pid:9928,providerId:0x0 Main(parent link):Unidentified Provider (managed:MS.Internal.Automation.ElementProxy, PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)] Element Properties (has/is info) $UIA_HasKeyboardFocusPropertyId False $UIA_IsContentElementPropertyId True $UIA_IsControlElementPropertyId True $UIA_IsDataValidForFormPropertyId False $UIA_IsDialogPropertyId False $UIA_IsEnabledPropertyId True $UIA_IsKeyboardFocusablePropertyId True $UIA_IsOffscreenPropertyId False $UIA_IsPasswordPropertyId False $UIA_IsPeripheralPropertyId False $UIA_IsRequiredForFormPropertyId False Control Patterns (element actions) $UIA_IsLegacyIAccessiblePatternAvailablePropertyId True (LegacyIAccessiblePattern) $UIA_IsRangeValuePatternAvailablePropertyId True (RangeValuePattern) $UIA_IsSynchronizedInputPatternAvailablePropertyId True (SynchronizedInputPattern) Control Pattern Properties $UIA_LegacyIAccessibleChildIdPropertyId 0 $UIA_LegacyIAccessibleDefaultActionPropertyId $UIA_LegacyIAccessibleDescriptionPropertyId $UIA_LegacyIAccessibleHelpPropertyId $UIA_LegacyIAccessibleKeyboardShortcutPropertyId $UIA_LegacyIAccessibleNamePropertyId $UIA_LegacyIAccessibleRolePropertyId 51 = $ROLE_SYSTEM_SLIDER $UIA_LegacyIAccessibleStatePropertyId 1048576 = $STATE_SYSTEM_FOCUSABLE $UIA_LegacyIAccessibleValuePropertyId 0 $UIA_RangeValueIsReadOnlyPropertyId False $UIA_RangeValueLargeChangePropertyId 1 $UIA_RangeValueMaximumPropertyId 691199.9999999 $UIA_RangeValueMinimumPropertyId 0 $UIA_RangeValueSmallChangePropertyId 0.1 $UIA_RangeValueValuePropertyId 2.47032822920623e-319 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*) RangeValue Pattern Methods SetValue(ushort) CurrentIsReadOnly(long*) CurrentMaximum(ushort*) CurrentMinimum(ushort*) CurrentLargeChange(ushort*) CurrentSmallChange(ushort*) CurrentValue(ushort*) SynchronizedInput Pattern Methods StartListening(long) Cancel() Parents from Desktop Pane: Desktop 1 Window: Playback Parent to child index In addition to this problem, I am unable to press the start button with an autoit script or by using inspect.exe=>Action=>Toggle() or inspect.exe=>Action=>DoDefaultAction(). I'll post that after solving the current problem.
-
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")
- 12 replies
-
- uiautomation
- simplespy
-
(and 2 more)
Tagged with:
-
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.
-
- treewalker
- uiautomation
-
(and 1 more)
Tagged with:
-
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.
-
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?