zenocon Posted November 27, 2017 Posted November 27, 2017 I have a winforms app with multiple tabs on a tab control, and I'm trying to tab to one of them. I'm trying to use the Invoke pattern but it is not working. Apparently a tab doesn't implement invoke? What other pattern can I try? expandcollapse popup#include "../uia/UIA_V0_64/UIAWrappers.au3" #include "../uia/UIA_V0_64/CUIAutomation2.au3" AutoItSetOption("MustDeclareVars", 1) Example() Func Example() ; Get Handle to the application Local $hWindow = WinGetHandle("Service/STG") If Not $hWindow Then Return ConsoleWrite( "Window handle ERR" & @CRLF ) ConsoleWrite( "Window handle OK" & @CRLF ) WinActivate($hWindow) ; 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 ) Local $pCondition, $pCondition1, $pCondition2 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TabItemControlTypeId, $pCondition1) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Service/STG", $pCondition2) $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition ) If Not $pCondition Then Return ConsoleWrite("Property condition ERR" & @CRLF) ; Find the Service/STG Tab so we can click it Local $pTab, $oTab $oWindow.FindFirst($TreeScope_Descendants, $pCondition, $pTab) $oTab = ObjCreateInterface($pTab, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oTab) Then Return ConsoleWrite("Find Service tab ERR" & @CRLF) ; Invoke the Service/STG Tab Local $pInvoke, $oInvoke $oTab.GetCurrentPattern($UIA_InvokePatternId, $pInvoke) $oInvoke = ObjCreateInterface( $pInvoke, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern ) If Not IsObj( $oInvoke ) Then Return ConsoleWrite( "Invoke object ERR" & @CRLF) $oInvoke.Invoke()
junkew Posted November 27, 2017 Posted November 27, 2017 See manual https://msdn.microsoft.com/en-us/library/windows/desktop/ee671649(v=vs.85).aspx Select or mousemove and mouseclick based on size of the tab FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
zenocon Posted November 27, 2017 Author Posted November 27, 2017 Thank you junkew -- _UIA_Action($oTab, "setfocus") also appears to do the trick.
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