Jump to content

How To Click on Tab Control UIA_TabItemControlTypeId


zenocon
 Share

Recommended Posts

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?

#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()

 

Link to comment
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
 Share

×
×
  • Create New...