Jump to content

NetFramework example GUI to use them with UIAutomation


Recommended Posts

I have a project in mind that I would like to share.
I would like to create example windows with standard elements like ComboBox, ListView, some Button, some text, some edit field.

Nothing special just simple Window.Net form that can be created with this following UDF:

or this one:


The main idea is to easily provide possible modifications to the "Testing GUI Window", and no need for any other tool than the AutoIt + SciTE kit.

Such "Testing GUI Window" will be very useful later on topic/threads/projects like:

As I am not very familiar with NetFramework, I would like to ask for help with this project.

Thanks in advance for any help.




Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *


My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

  • mLipok changed the title to NetFramework example GUI to use them with UIAutomation
  • What do you mean with "Testing GUI Window"? 
    • Are you referring to au3inf?
  • The main idea is to easily provide possible modifications to the "Testing GUI Window", and no need for any other tool than the AutoIt + SciTE kit.
    • But how do you see this new tool then?
  • Not sure what you miss in the current tool set exactly?
    • simplespy and uiaspy deliver code snippets for all elements that are uia compatible
  • "I would like to create example windows with standard elements like ComboBox, ListView, some Button, some text, some edit field."
    • So this means: In each example window one specific element? 
    • What would you do then with such kind of example window.
Link to comment
Share on other sites

You should get free version of Visual Studio and make an example form with all the controls you want to interact with. With a C# project it should be pretty easy to drag and drop, then build. then you can use those udfs on it. 


Visual Studio 2022 Community Edition – Download Latest Free Version (microsoft.com)


all you need is the .NET development Desktop to do this, they may have samples you can just build and run based on Winforms or new xml forms, oh whats their name, getting old

Edited by Earthshine

My resources are limited. You must ask the right questions


Link to comment
Share on other sites

By default, no UIA code in C# or VB.NET applications
Note that an example GUI created as described in first post will generally not contain UIA code to automate the controls. Only standard Windows controls that can already be automated with classic code will also be able to automate with UIA code. Other controls including all the interesting .NET controls, e.g. the DataGridView control, which is not derived from the standard controls, can only be automated with MSAA code. By default, a program created with C# or VB.NET code will not contain UIA code except for the standard Windows controls. Otherwise only MSAA code.

At top of this post is an example with the DataGridView control, which clearly demonstrates this. tst00.vb and tst00.au3 can be found in GridControls.7z at bottom of said post. Running tst00.au3 creates a GUI like this:


UIASpy shows the element tree structure for all controls throughout the GUI as follows: 

0000    Window: WindowsForms10.Window.8.app.0.3e799b_r35_ad1
0001        Pane: WindowsForms10.Window.8.app.0.3e799b_r35_ad1
0002            Button: Add Row
0003            Button: Delete Row
0004        Table: DataGridView
0005            Custom: Top Row
0006                Header: Title
0007                Header: Artist
0008                Header: Album
0009                Header: Release Date
0010                Header: Track
0011            Custom: Row 0
0012                Custom: Title Row 0
0013                Custom: Artist Row 0
0014                Custom: Album Row 0
0015                Custom: Release Date Row 0
0016                Custom: Track Row 0
0017            Custom: Row 1
0018                Custom: Title Row 1
0019                Custom: Artist Row 1
0020                Custom: Album Row 1
0021                Custom: Release Date Row 1
0022                Custom: Track Row 1
0023            Custom: Row 2
0024                Custom: Title Row 2
0025                Custom: Artist Row 2
0026                Custom: Album Row 2
0027                Custom: Release Date Row 2
0028                Custom: Track Row 2
0029            Custom: Row 3
0030                Custom: Title Row 3
0031                Custom: Artist Row 3
0032                Custom: Album Row 3
0033                Custom: Release Date Row 3
0034                Custom: Track Row 3
0035            Custom: Row 4
0036                Custom: Title Row 4
0037                Custom: Artist Row 4
0038                Custom: Album Row 4
0039                Custom: Release Date Row 4
0040                Custom: Track Row 4
0041            Custom: Row 5
0042                Custom: Title Row 5
0043                Custom: Artist Row 5
0044                Custom: Album Row 5
0045                Custom: Release Date Row 5
0046                Custom: Track Row 5
0047            Custom: Row 6
0048                Custom: Title Row 6
0049                Custom: Artist Row 6
0050                Custom: Album Row 6
0051                Custom: Release Date Row 6
0052                Custom: Track Row 6
0053            Custom: Row 7
0054                Custom: Title Row 7
0055                Custom: Artist Row 7
0056                Custom: Album Row 7
0057                Custom: Release Date Row 7
0058                Custom: Track Row 7
0059        TitleBar
0060            MenuBar: System
0061                MenuItem: System
0062            Button: Minimize
0063            Button: Maximize
0064            Button: Close

Recognized controls can be automated with UIA code. Custom controls can only be automated with MSAA code.

The $UIA_ProviderDescriptionPropertyId, which is a text string, provides some information about how a window or control can be automated: 

[pid:4496,hwnd:0x602D2 Main:Nested [pid:2976,hwnd:0x602D2 Main(parent link):Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll)]; Nonclient:Microsoft: Non-Client Proxy (unmanaged:uiautomationcore.dll); Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)]

If the string contains Proxy substrings such as Microsoft: MSAA Proxy or Microsoft: HWND Proxy, it can be automated with MSAA code or classic code. There are many different of these Proxy substrings.

To add more UIA code to the program take a look at the UI Automation Provider Programmer's Guide. It's not necessarily completely trivial.

I don't know if it's possible through Visual Studio to more easily add at least default UIA code to actual .NET controls implemented in C# or VB.NET. Maybe junkew or Earthshine know something about this.

At first glance, I think it's easier to test with existing programs that already contain more complete UIA code e.g. File Explorer and Calculator. Whether testing with File Explorer and Calculator or with .NET programs is completely indifferent to the UIA code. The UIA code to click a button, a menu item, set a selection in a table, or expand/collapse a treeview control element as well as other automation actions is exactly the same for all programs, as long as the controls support the required UIA code. 

In UIA code, automation actions as mentioned above are implemented through pattern interfaces.

There are already a number of examples of the use of these automation actions and similar pattern interfaces in this post. Then it might be the easiest place to start. If you want, you can test some of the examples in other programs.

Link to comment
Share on other sites

@Larsjm you are correct in that C# WPF apps do not automatically provide for client utilization of UIAutomation. The app developer can add that in.


UI Automation Overview - .NET Framework | Microsoft Docs

UI Automation of a Custom Control - WPF .NET Framework | Microsoft Docs

Server-Side UI Automation Provider Implementation - .NET Framework | Microsoft Docs

Edited by Earthshine

My resources are limited. You must ask the right questions


Link to comment
Share on other sites

  • Still adding it in by your developers is a lot of googling around in bits and pieces on how for example automationid can be set for WPF
<ListView IsEnabled="{Binding TestSelectorEnabled}" x:Name="ListView1"  ItemsSource="{Binding TestsDataTable}" SelectedValue="{Binding SelectedTest}" SelectedValuePath="TestName" Height="180" View="{Binding GridView}"  TabIndex="0" MinWidth="1" Focusable="False">
                <Style TargetType="ListViewItem">
                    <Setter Property="AutomationProperties.AutomationId" Value="{Binding Path=DataContext.TestsViewModel.ListItemCounter, StringFormat='dataitem{0:F0}', UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListView}}"/>



  • Even for HTML 5 I have never found an easy reference for UIA and what developers should add to their HTML to get automationid in UIA nicely filled  (id seems best but then automationid jumps sometimes from textbox element to a div element and still have then to search the next innerchild with a treewalker.
    https://www.w3.org/TR/core-aam-1.2/#mapping_state-property_table is the best part I found for HTML.
    Would be nice if it could be handled more with UIA so then no mix of webdriver and UIA stuff in framework.
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

  • Create New...