Jump to content

Is there a way to specify a UIAutomation control in a way that yields faster actions?


Recommended Posts

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")

 

Link to post
Share on other sites

The advantage of using the wrapper functions is that they are easy to use. The disadvantage is that they execute a large number of code lines. Especially _UIA_Action. The only thing you can do to increase performance is to avoid the wrapper functions and call the interface methods in CUIAutomation2.au3 directly.

You can look at some of my examples in the UI Automation thread to see how to do it.

Link to post
Share on other sites

Next version I hope to have better speed of the uiaWrappers but I am not sure If I cause 2 seconds delay.

I know the logic in the wrappers is also if no treehierarchy is specified fallback to desktop and start searching the whole tree which can be huge and timeconsuming (when you turn logging on you can see what happens in detail and how many objects are traversed before finding the element)

Func _UIA_getFirstObjectOfElement($obj, $str, $treeScope) is probably quicker as it does not do a findall

I will put on my TODO some logic like

if in UIA_Action 1 property is used for finding an element directly call directly something like below

;- Change Func _UIA_getFirstObjectOfElement

$propertyID = $UIA_NamePropertyId ;- Or automation id property or .....
$tVal= ..... ;- property value

$UIA_oUIAutomation.createPropertyCondition($propertyID, $tval, $pCondition)
$oCondition = ObjCreateInterface($pCondition, $sIID_IUIAutomationPropertyCondition, $dtagIUIAutomationPropertyCondition)
$t = $obj.Findfirst($treeScope, $oCondition, $UIA_pUIElement)
$UIA_oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)

 

Link to post
Share on other sites

Thanks guys.  I was really struggling to follow even the simple examples, but after writing the main functionality of populating a form in C#, I was able to understand the Automation class a bit further -- without the abstraction of AutoIT.  Then, I turned my attention back to AutoIT and with your guidance above and the C# experience, I wrote a simple UDF for my specific case.  Not only do I appreciate the more AutoIT native syntax, the speed is now fully reasonable.  The _UAI_SetVar and _UAI_Action methods (using the unaltered UIAWrappers.au3) takes ~4-seconds to enter a user name into a text field.  The revised code below populates that field in ~20-milliseconds.  Yeah!  Thanks again for the guidance.

Sample Code:

#include "UIAutomation.au3"

; find parent element
$hWindow = WinGetHandle('Sunlight MiniOmni')
$aeParent = _getAeFromHandle($hWindow)

; find target element
$aeTarget = _getAeFromCondition($aeParent, $UIA_AutomationIdPropertyId, 'txtUserName')

; set target element value
_setAeValue($aeTarget, 'username here')

My Simple UDF (UIAutomation.au3):

#include "CUIAutomation2.au3"

Global $aInterfaceObj

_UIAutomationInit()


Func _UIAutomationInit()
    $aInterfaceObj  = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
    Return IsObj($aInterfaceObj) ? $aInterfaceObj : False
EndFunc ;  _UIAutomationInit()


Func _setAeValue($aeTarget, $valueStr)
    Local $patternPointer

    If Not IsObj($aeTarget) Then Return False

    $aeTarget.GetCurrentPattern($UIA_ValuePatternId, $patternPointer)
    $aePattern = ObjCreateInterface( $patternPointer, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern)
    $aePattern.SetValue($valueStr)

EndFunc ;_setAeValue()


Func _getAeFromCondition($aeParent, $propType, $propStr)
    Local $targetPointer, $propCondInterfaceObj

    If Not IsObj($aInterfaceObj) Then Return False
    If Not IsObj($aInterfaceObj) Then Return False
    If Not IsObj($aeParent) Then Return False

    $aInterfaceObj.createPropertyCondition( $propType, $propStr, $propCondInterfaceObj )
    $aeParent.FindFirst( $TreeScope_Descendants, $propCondInterfaceObj, $targetPointer)
    $ae = ObjCreateInterface( $targetPointer, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )

    Return IsObj($ae) ? $ae : False

EndFunc ; _getAeFromCondition()


Func _getAeFromHandle($hWindow)
    Local $winPointer

    If Not WinExists($hWindow) Then Return False
    If Not IsObj($aInterfaceObj) Then Return False

    $aInterfaceObj.ElementFromHandle( $hWindow, $winPointer )
    $ae = ObjCreateInterface( $winPointer, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )

    Return IsObj($ae) ? $ae : False
EndFunc ; _getAeFromHandle()

 

Link to post
Share on other sites

Findfirst is for sure match quicker and in your scenario your developers behave nicely on automationid.

The uiawrappers give 

A. Regular expression matching

B. Matching on index or ordinal value

C. Match with multiple properties

As said I will improve on single property and exact matching using findfirst

Link to post
Share on other sites
  • 2 weeks later...

Nice topic!

First i will learn, then i will ask forsome help later on :P

Really amazing job @junkew

Thanks adv.

@UPDATE:

On 19/02/2016 at 3:06 AM, bobmcrae said:

Thanks guys.  I was really struggling to follow even the simple examples, but after writing the main functionality of populating a form in C#, I was able to understand the Automation class a bit further -- without the abstraction of AutoIT.  Then, I turned my attention back to AutoIT and with your guidance above and the C# experience, I wrote a simple UDF for my specific case.  Not only do I appreciate the more AutoIT native syntax, the speed is now fully reasonable.  The _UAI_SetVar and _UAI_Action methods (using the unaltered UIAWrappers.au3) takes ~4-seconds to enter a user name into a text field.  The revised code below populates that field in ~20-milliseconds.  Yeah!  Thanks again for the guidance.

Sample Code:

#include "UIAutomation.au3"

; find parent element
$hWindow = WinGetHandle('Sunlight MiniOmni')
$aeParent = _getAeFromHandle($hWindow)

; find target element
$aeTarget = _getAeFromCondition($aeParent, $UIA_AutomationIdPropertyId, 'txtUserName')

; set target element value
_setAeValue($aeTarget, 'username here')

My Simple UDF (UIAutomation.au3):

#include "CUIAutomation2.au3"

Global $aInterfaceObj

_UIAutomationInit()


Func _UIAutomationInit()
    $aInterfaceObj  = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
    Return IsObj($aInterfaceObj) ? $aInterfaceObj : False
EndFunc ;  _UIAutomationInit()


Func _setAeValue($aeTarget, $valueStr)
    Local $patternPointer

    If Not IsObj($aeTarget) Then Return False

    $aeTarget.GetCurrentPattern($UIA_ValuePatternId, $patternPointer)
    $aePattern = ObjCreateInterface( $patternPointer, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern)
    $aePattern.SetValue($valueStr)

EndFunc ;_setAeValue()


Func _getAeFromCondition($aeParent, $propType, $propStr)
    Local $targetPointer, $propCondInterfaceObj

    If Not IsObj($aInterfaceObj) Then Return False
    If Not IsObj($aInterfaceObj) Then Return False
    If Not IsObj($aeParent) Then Return False

    $aInterfaceObj.createPropertyCondition( $propType, $propStr, $propCondInterfaceObj )
    $aeParent.FindFirst( $TreeScope_Descendants, $propCondInterfaceObj, $targetPointer)
    $ae = ObjCreateInterface( $targetPointer, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )

    Return IsObj($ae) ? $ae : False

EndFunc ; _getAeFromCondition()


Func _getAeFromHandle($hWindow)
    Local $winPointer

    If Not WinExists($hWindow) Then Return False
    If Not IsObj($aInterfaceObj) Then Return False

    $aInterfaceObj.ElementFromHandle( $hWindow, $winPointer )
    $ae = ObjCreateInterface( $winPointer, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )

    Return IsObj($ae) ? $ae : False
EndFunc ; _getAeFromHandle()

 

I'm getting:

Unknown function name.:
$aeParent = _getAeFromHandle($hWindow)
$aeParent = ^ ERROR

Some idea why?

Thanks adv.

Edited by Chiitus
Link to post
Share on other sites
  • 1 month later...

how did you find this

'txtUserName'

(which way did you read it?)

and why did you use it together with

$UIA_AutomationIdPropertyId

Can you also give me direct link to this application

Sunlight MiniOmni

then I can download it, use "simple spy" and try to understand your code to learn UIA

Edited by maniootek
Link to post
Share on other sites
  • 2 years later...

@junkew Thanks so much for your UDF, it makes things much faster but can you include an "action" function in your UDF?


I'm using your script to automate mstsc.exe in win2016, I can inject username + password thanks to your code, but how do i click on the ok button?

Thanks.

Link to post
Share on other sites

That user hasn't been here since 2016, I'm not sure he'll be responding.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to post
Share on other sites

sn1kzZ, Here is a list of control types and supported patterns (actions).

You should create a new thread with your own question. Add information about application, controls and actions. Then it should not be impossible to make some fast code.

 

You can also google this way:

LarsJ CUIAutomation2.au3 site:autoitscript.com

Then you'll get a list of examples with very fast code.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Sayed
      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")  
       
    • By rmckay
      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.
    • By rmckay
      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
    • By rmckay
      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.
    • By adityaparakh
      Hello ,
      I am trying to fetch data and control a Windows Program.
      The data isn't reflected in the Au3Info tool , hence used SimpleSpy UIA , for trying.
      The code is able to fetch only one row at a time.
      Most Strangely , the code doesn't retreive the same specified row consistently.
      If I run the same code , under same circumstance , it is still fetching different rows.
      This was when op2 and op3 were zero. I would not like to use this at all.

      Also , it takes 3 seconds for it search down the hiearchy and reach the row.
      I will need to fetch ALL the rows continuously for 6 hours every second , in a minimized state.
      Can you please help.
      Attached :
      1. AuInfo summary
      2. Code
      3. Simple Spy Summary
      The Actions I am trying to do (in a Minimzed State - not affecting usage of computer for other purposes)
      1. Fetch all Rows (number of rows will not always be constant
      2. Press the Check box for a specific row(s)
      3. Press the squareOff button on top
      Thanks a lot
       
       
      #include <MsgBoxConstants.au3> #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) Local $oP8=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=MO Trader;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.3e799b_r8_ad1", $treescope_children) _UIA_Action($oP8,"setfocus") Local $oP7=_UIA_getObjectByFindAll($oP8, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.3e799b_r8_ad1", $treescope_children) _UIA_Action($oP7,"setfocus") Local $oP6=_UIA_getObjectByFindAll($oP7, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.3e799b_r8_ad1", $treescope_children) _UIA_Action($oP6,"setfocus") Local $oP5=_UIA_getObjectByFindAll($oP6, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.3e799b_r8_ad1", $treescope_children) _UIA_Action($oP5,"setfocus") Local $oP4=_UIA_getObjectByFindAll($oP5, "Title:=Day Net Position;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.3e799b_r8_ad1", $treescope_children) _UIA_Action($oP4,"setfocus") Local $oP3=_UIA_getObjectByFindAll($oP4, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.3e799b_r8_ad1", $treescope_children) _UIA_Action($oP3,"setfocus") Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=0.0000;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.3e799b_r8_ad1", $treescope_children) _UIA_Action($oP2,"setfocus") Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=0.0000;controltype:=UIA_TableControlTypeId;class:=WindowsForms10.Window.8.app.0.3e799b_r8_ad1", $treescope_children) _UIA_Action($oP1,"setfocus") Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Data Panel;controltype:=UIA_CustomControlTypeId;class:=", $treescope_children) ;~ First find the object in the parent before you can do something Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=Row 12;ControlType:=UIA_CustomControlTypeId", $treescope_subtree) _UIA_action($oUIElement,"click") Local $string = _UIA_action($oUIElement,"getValue") MsgBox($MB_OK,"", $string) Local $oUIElement2=_UIA_getObjectByFindAll($oP0, "title:=Row 6;ControlType:=UIA_CustomControlTypeId", $treescope_subtree) _UIA_action($oUIElement2,"click") Local $string2 = _UIA_action($oUIElement2,"getValue") MsgBox($MB_OK,"", $string2)  


      SimpleSpy Row.txt
×
×
  • Create New...