Jump to content
zenocon

Does anyone know how to set the Automation Index in WinForms

Recommended Posts

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

Share this post


Link to post
Share on other sites
zenocon

Ugh it appears it is just LIFO (Last In First Out).  It's like a stack, push a new element into a container and it is at the top of the list.  I don't see any other way to modify.

Share this post


Link to post
Share on other sites
zenocon

Hi junkew -- Tab Index does not affect Automation Index.  I indicated that in my first post above.  The only thing that affects it, as far as I can tell, is the order you add child components to a parent.  

Edited by zenocon

Share this post


Link to post
Share on other sites
junkew

Not sure if we talk about the same but it seems possible when you read the instructions

Those numbers are the order that your controls will be hit when pressing the 'Tab' key. When in View Tab Order mode, you can click on the controls in the order that you want them to be hit. That will re-order them. You'll notice that the numbers start changing as you click

In my visual studio 2015 community edition and vs 2013 premium I just can choose menu view, taborder and then change the taborder

 

Share this post


Link to post
Share on other sites
LarsJ

zenocon, If you by the Automation Index means the index in the Automation element array as returned by eg. the FindAll method when this method is executed on a container control (window, group, pane) containing a set of similar controls, then you cannot set this index. And you don't have to set the index.

The important thing is that the controls always have the same position in the element array. If you execute FindAll on your fake GUI and on your real GUI and figures out that control number 3 in the fake GUI matches number 7 in the real GUI, then number 3 will always match number 7. You can simply hardcode these numbers in your script.

The index in the element array sometimes matches the tab order and sometimes not.

Share this post


Link to post
Share on other sites
zenocon

In Visual Studio, there is a Document View which shows all the UI elements.  By switching to that view it shows you the parent/child hierarchy of all the elements, and it allows you to drag-n-drop elements in whatever order or hierarchy you want.  Once I figured this out, I was able to re-organize my fake UI to match the output of my inspect.exe results.

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
      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?

    • zenocon
      By zenocon
      Hi,
      If I'm reading the code in UIAWrappers.au3 correctly, the function _UIA_getObjectByFindAll( ) uses the UIElement.FindAll with the true condition, so it would find any elements that match the treescope passed in.  This populates an array, and then it iterates through them and tries matching the properties that were passed into _UIA_getObjectByFindAll and returns the first element that is the best match.
      I understand one can use the index or relativeindex properties to target a specific child, let's say when you have a panel that has a bunch of edit fields.  If you know the specific index of the one you want you can use the index to get it back, but what if I want to return, say the whole array of UIElements that match a specific type.
      Is my best option here to just use the .FindAll( ) function directly and set my own condition to match the controltypeid?
       
       
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.