Jump to content
zenocon

How To Click on Tab Control UIA_TabItemControlTypeId

Recommended Posts

zenocon

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

 

Share this post


Link to post
Share on other sites
zenocon

Thank you junkew -- _UIA_Action($oTab, "setfocus") also appears to do the trick.

Share this post


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

  • Similar Content

    • RomanY
      By RomanY
      Good evening!
      Can somebody help me with getting text from wpf controls. With a help of inspect.exe I found element selector and now I need to get text from some button and assert that text is  as expected?
       
    • souldjer777
      By souldjer777
      Good Evening Everyone
      Long time since I've been in the forums - missing AutoIt and programming dearly - but on with the question... I hope this one is easy
      I am using SimpleSpy / UIAWrappers.au3 to automate an application. I basically have a "Stop" button that I am waiting to change from UIA_IsEnabled:= <False> to UIA_IsEnabled:= <True>
      How do I check for the UIA_IsEnabled condition ?  Of course SimpleSpy gives all the details of GUI elements... but what code do I use to just check the GUI "Stop" buttons UIA_IsEnabled condition?
      Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=Stop;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)
      Thanks!
    • careca
      By careca
      Hey there, i have the code from simplespy but have no idea about what to use, got the UIA_V0_64 files.
      I look at the examples but i get lost, i ask for guideance in this matter.
      Best regards.

       
      To get to this window simply run:
      control.exe /name Microsoft.DefaultPrograms /page pageFileAssoc
      select a filetype and click "change program"
    • zenocon
      By zenocon
      I'm building a fake WinForms GUI that I'm using to test.  In one instance, it has a panel with a number of text elements.  I have the inspect.exe output of the real target UI that I'm trying to automate, but I'm trying to build a fake one now that emulates it so I can more easily test.
      The problem is the order of the text elements in the pane is different, and I'm having a helluva time trying to figure out how to set the order -- if that's even possible.  The WinForms TabIndex property doesn't do it.  There is no Index property on it otherwise.  I'm worried it may not even be possible, so I figured I'd ask here.
      Thank in advance
    • zenocon
      By zenocon
      Consider the following image.  I'm interested in all of the text elements embedded in the last pane called "Power Container".  Unfortunately, this pane is embedded in 8 other panes with the same name and no other identifying characteristics.  I think I can get to the target pane using indexrelative.
      Local $powerContainer = _UIA_getObjectByFindAll($cPowerMain, "controltype:=UIA_PaneControlTypeId;Name:=Power Container;indexrelative:=8", $treescope_subtree) If Not IsObj($powerContainer) Then Return ConsoleWrite("Could not find Power Container pane") So, now I have the pane, but I want to target individual text elements.  They do seemingly have AutomationIds so I think I can use that as a selector.  Problem is I'm building a fake WinForms GUI to test with since I don't have access to the real UI to automate for testing purposes, and with WinForms, there is no way to set the AutomationId.  There is no other identifying information on these text elements.  Their Name property contains the actual data, which varies.  Except for the labels that sit in from of them.
      The way it is built it looks like this:
       
      My question is this: I know I can select to get the one with the static label value "Tag#"
      Local $tagLabel = _UIA_getObjectByFindAll($powerContainer, "controltype:='UIA_TextControlTypeId;Name:=Tag#", $treescope_subtree) Now, what I want to do is navigate to get the next sibling of this element.  It doesn't look like the API allows me to do this?  I think what I have to do is get a RawViewWalker and just iterate through all of them and inspect each one and figure out if it is what I'm looking for.   Does this seem correct?
      Is there a better way to achieve this?

×