junkew Posted April 12, 2016 Share Posted April 12, 2016 Speed in UIAWrappers is sometimes slow if finding by non matching properties. The wrappers are "SMART" in such a way that if it cannot find initially in the right context it starts searching in the parents and in worst case in parents and the whole subtree. Will make that configurable in future. See comments in code nearby "Do not directly search all children and grandchildren but take 2 step approach as frequently only looking in the direct childs" FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
maniootek Posted April 23, 2016 Author Share Posted April 23, 2016 On 12.04.2016 at 11:29 AM, LarsJ said: I don't think there is anything wrong. But there is no direct edit or text control descendants of the window object. The edit and text controls are probably child elements of the custom controls. Sorry, I did some mistake. My code is working good now. Changing ControlTypeID did not bring huge execute time savings. Now I am working with other app now, which I think is better for UI Automation. All controls in this app have unique handle and unique UI Automation ID like: Quote Handle = 00050CFA AutomationID = 16603 I would like to do something more than read element title. I want to click on it now. I used code from this post: and this is my results: expandcollapse popup#include "CUIAutomation2.au3" Opt( "WinTitleMatchMode", 2 ) Global $aInterfaceObj _UIAutomationInit() ; find parent element $hWindow = WinGetHandle(' - my app name') $aeParent = _getAeFromHandle($hWindow) ; find target element $aeTarget = _getAeFromCondition($aeParent, $UIA_AutomationIdPropertyId, '16603') ; this is my unique AutomationID ConsoleWrite(GetCurrentPropertyValue($aeTarget, $UIA_NamePropertyId) & @CRLF) ;just ensure that this is my target element by checking its title ;how can I click (invoke?) on this element now? ;tried $aeTarget.Invoke but it does not work Func _UIAutomationInit() $aInterfaceObj = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) Return IsObj($aInterfaceObj) ? $aInterfaceObj : False EndFunc ; _UIAutomationInit() 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() Func GetCurrentPropertyValue( $obj, $id ) Local $tVal $obj.GetCurrentPropertyValue( $id, $tVal ) If Not IsArray( $tVal ) Then Return $tVal Local $tStr = $tVal[0] For $i = 1 To UBound( $tVal ) - 1 $tStr &= "; " & $tVal[$i] Next Return $tStr EndFunc Any idea? Link to comment Share on other sites More sharing options...
junkew Posted April 24, 2016 Share Posted April 24, 2016 Read the uiawrappers source or example 1-5. You have to get the interface pattern before you can invoke. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
maniootek Posted April 25, 2016 Author Share Posted April 25, 2016 15 hours ago, junkew said: Read the uiawrappers source or example 1-5. You have to get the interface pattern before you can invoke. Tried to add this function to my code Func Invoke($aeTarget) Local $patternPointer If Not IsObj($aeTarget) Then Return False $aeTarget.GetCurrentPattern($UIA_InvokePatternId, $patternPointer) $aePattern = ObjCreateInterface( $patternPointer, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern) $aePattern.Invoke() EndFunc but I got error Quote Variable must be of type "Object": $aePattern.Invoke() $aePattern^ ERROR I also tried invoke that element with UIAWrappers but it only set focus of main window of my app, does not invoke it. this is my element property Quote ~ ~ ~ Title = My app element title ~ ~ ~ Class = AfxWnd80u ~ ~ ~ Ctrl type = 50033 ~ ~ ~ Ctrl name = okienko ~ ~ ~ Value = ~ ~ ~ Handle = 000C162E ~ ~ ~ AutomationID = 16603 I think ctrl type "50033" is not "invokeable" When I tried to use "click" command via (using $UIA_BoundingRectanglePropertyId) then it works. Any idea how to click on that element with other way without using mousemove/mouseclick action? Link to comment Share on other sites More sharing options...
junkew Posted April 25, 2016 Share Posted April 25, 2016 Check with inspect.exe FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
maniootek Posted April 26, 2016 Author Share Posted April 26, 2016 11 hours ago, junkew said: Check with inspect.exe Yes I did. Quote ControlType: UIA_PaneControlTypeId (0xC371) IsInvokePatternAvailable: false @junkew and @LarsJ Thank you guys for all your help with UIA. Now I am able to automate a lot more applications than before. 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