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 * for 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) *

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 *

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: 2021-10-18

Link to post
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 post
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 post
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 post
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 post
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 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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ahmet

      I am trying to catch closing of a window via the UIA. End goal is to detect closing of a Chrome's tab, but currently I am having issues with the window created with GUICreate.
      I have modified example from UI Automation Events .
      I added GUI to show issues. Inside this GUI AutomationEventHandler is attached to all buttons. There are two buttons created by the script. One displays the message while the other closes the GUI.
      There are also buttons from the title bar. I attached automation event handlers to those buttons too.
      Currently script notifies me if I click on "OK" button. If I click on any of "Close", "X" or "Minimize" button then I do not get any notification.
      Is it possible for the script to notify when any of the buttons mentioned above is clicked?
      #include "..\Includes\UIAEH_AutomationEventHandler.au3" $hMain=GUICreate("UI Automation Event Handler") $idButtonOK=GUICtrlCreateButton("OK",10,10) $idButtonClose=GUICtrlCreateButton("Close",70,10) $idOutput=GUICtrlCreateEdit("",10,35,300,300) GUISetState() UIAEH_AutomationEventHandlerCreate() If Not IsObj( $oUIAEH_AutomationEventHandler ) Then Exit ConsoleWrite( "$oUIAEH_AutomationEventHandler ERR" & @CRLF ) ConsoleWrite( "$oUIAEH_AutomationEventHandler OK" & @CRLF ) Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation) ;~ Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation8, $sIID_IUIAutomation6, $dtag_IUIAutomation6 ) If Not IsObj($oUIAutomation) Then Exit ConsoleWrite("$oUIAutomation ERR" & @CRLF) ConsoleWrite("$oUIAutomation OK" & @CRLF) Local $pIUIAutomationCacheRequest, $oIUIAutomationCacheRequest $oUIAutomation.CreateCacheRequest( $pIUIAutomationCacheRequest ) $oIUIAutomationCacheRequest = ObjCreateInterface( $pIUIAutomationCacheRequest, $sIID_IUIAutomationCacheRequest, $dtag_IUIAutomationCacheRequest ) If Not IsObj( $oIUIAutomationCacheRequest ) Then Exit ConsoleWrite("$oIUIAutomationCacheRequest Error" & @CRLF) If $oIUIAutomationCacheRequest.AddPattern($UIA_InvokePatternId) Then Exit ConsoleWrite("$oIUIAutomationCacheRequest.AddPattern Error" & @CRLF) If $oIUIAutomationCacheRequest.put_AutomationElementMode( $AutomationElementMode_Full) Then Exit ConsoleWrite("$oIUIAutomationCacheRequest.put_AutomationElementMode Error" & @CRLF) ;~ $pIUIAutomationCacheRequest=0 ConsoleWrite("--- Find window/control ---" & @CRLF) Local $pPane1, $oGUI $oUIAutomation.ElementFromHandle($hMain,$pPane1) $oGUI = ObjCreateInterface($pPane1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement) If Not IsObj($oGUI) Then Exit ConsoleWrite("$oGUI ERR" & @CRLF) ConsoleWrite("$oGUI OK" & @CRLF) Local $sNamePropperty, $sClassName1 $oGUI.GetCurrentPropertyValue($UIA_NamePropertyId, $sNamePropperty) ConsoleWrite("Name:" & $sNamePropperty & @CRLF) $oGUI.GetCurrentPropertyValue($UIA_ClassNamePropertyId, $sClassName1) ConsoleWrite("ClassName:" & $sClassName1 & @CRLF) ConsoleWrite("--- Find buttons ---" & @CRLF) Local $pCondition0 $oUIAutomation.CreatePropertyCondition($UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition0) If Not $pCondition0 Then Exit ConsoleWrite("$pCondition0 ERR" & @CRLF) ConsoleWrite("$pCondition0 OK" & @CRLF) Local $pButtons, $oButton $oGUI.FindAll($TreeScope_Descendants, $pCondition0, $pButtons) ConsoleWrite("$oGUI FindAll()" & @CRLF) Local $oUIElementArray1, $iLength1 ; $pButtons is a pointer to an UI Automation element array $oUIElementArray1 = ObjCreateInterface($pButtons, $sIID_IUIAutomationElementArray, $dtag_IUIAutomationElementArray) $oUIElementArray1.Length($iLength1) If Not $iLength1 Then Exit ConsoleWrite("$iLength1 = 0 ERR" & @CRLF) ConsoleWrite("$iLength1 = " & $iLength1 & @CRLF) ; --- Code Snippets --- ConsoleWrite("--- Code Snippets ---" & @CRLF) Local $pElement1, $oElement1, $pCondition0 Local $sClassName1, $sLocalizedControlType1, $sName1, $hNativeWindowHandle1, $iError For $i = 0 To $iLength1 - 1 $oUIElementArray1.GetElement($i, $pElement1) $oElement1 = ObjCreateInterface($pElement1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement) $oElement1.GetCurrentPropertyValue($UIA_NamePropertyId, $sName1) ConsoleWrite("$sName1 = " & $sName1 & @CRLF) ;~ $iError = $oUIAutomation.AddAutomationEventHandler( $UIA_Invoke_InvokedEventId, $pElement1, $TreeScope_Children, 0, $oUIAEH_AutomationEventHandler ) ;~ $iError = $oUIAutomation.AddAutomationEventHandler( $UIA_Invoke_InvokedEventId, $pElement1, $TreeScope_Element, 0, $oUIAEH_AutomationEventHandler ) $iError = $oUIAutomation.AddAutomationEventHandler( $UIA_Invoke_InvokedEventId, $pElement1, $TreeScope_Element, $pIUIAutomationCacheRequest, $oUIAEH_AutomationEventHandler ) If $iError Then Exit ConsoleWrite( "AddAutomationEventHandler() ERR" & @CRLF ) ConsoleWrite( "AddAutomationEventHandler() OK" & @CRLF ) Next While Sleep(10) Switch GUIGetMsg() Case -3, $idButtonClose GUIDelete($hMain) MsgBox(0,"About to exit","") Quit() Case $idButtonOK GUICtrlSetData($idOutput,"You clicked on button" & @CRLF,"a") EndSwitch WEnd Func Quit() UIAEH_AutomationEventHandlerDelete() Exit EndFunc ; This is the function that receives events Func UIAEH_AutomationEventHandler_HandleAutomationEvent( $pSelf, $pSender, $iEventId ) ; Ret: long Par: ptr;int ConsoleWrite( @CRLF & "UIAEH_AutomationEventHandler_HandleAutomationEvent: $iEventId = " & $iEventId & @CRLF ) ;~ Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) ; Windows 7 ;Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement2, $dtag_IUIAutomationElement2 ) ; Windows 8 ;Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement3, $dtag_IUIAutomationElement3 ) ; Windows 8.1 ;Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement4, $dtag_IUIAutomationElement4 ) ; Windows 10 First Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) ; Windows 10 Last $oSender.AddRef() GUICtrlSetData($idOutput,"InvokedEvent:" & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_NamePropertyId ) & @CRLF,"a") ConsoleWrite( "Title = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_NamePropertyId ) & @CRLF & _ "Class = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_ClassNamePropertyId ) & @CRLF & _ "Ctrl type = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_ControlTypePropertyId ) & @CRLF & _ "Ctrl name = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_LocalizedControlTypePropertyId ) & @CRLF & _ "Handle = " & "0x" & Hex( UIAEH_GetCurrentPropertyValue( $oSender, $UIA_NativeWindowHandlePropertyId ) ) & @CRLF & _ "Value = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_ValueValuePropertyId ) & @CRLF ) MsgBox(0,"","Invoke event") Return 0x00000000 ; $S_OK #forceref $pSelf EndFunc ; Auxiliary function (for simple properties only) ; There must be only one instance of this function Func UIAEH_GetCurrentPropertyValue( $oSender, $iPropertyId ) Local $vPropertyValue $oSender.GetCurrentPropertyValue( $iPropertyId, $vPropertyValue ) Return $vPropertyValue EndFunc  
    • By buymeapc
      I was looking for a way to use the CLR functions to check a SQL 2016 database state, but I've been unable to find an example that I can get to work. Any help would be appreciated. Here's what I have, which always errors when I try to set the connection string and I'm not sure why. Thanks!
      #include ".\Includes\CLR.au3" #include ".\Includes\CLR Constants.au3" JustATest() Func JustATest() Local $oAssembly = _CLR_LoadLibrary("System.Data") ConsoleWrite("$oAssembly: " & IsObj($oAssembly) & @CRLF) Local $oSQLConn = _CLR_CreateObject($oAssembly, "System.Data.SqlClient.SqlConnection") ConsoleWrite("$oSQLConn: " & IsObj($oSQLConn) & @CRLF) $oSQLConn.ConnectionString = "Server=serverip;Database=dbname;UID=user;PWD=aaaa;" $oSQLConn.Open EndFunc Edit: I am using ptrex's CLR UDF from here:
    • By adityaparakh
      Hello ,
      I am trying to fetch data and control a Windows Program.
      The data isn't reflected in the Au3Info tool , hence used SimpleSpy UIA , for trying.
      The code is able to fetch only one row at a time.
      Most Strangely , the code doesn't retreive the same specified row consistently.
      If I run the same code , under same circumstance , it is still fetching different rows.
      This was when op2 and op3 were zero. I would not like to use this at all.

      Also , it takes 3 seconds for it search down the hiearchy and reach the row.
      I will need to fetch ALL the rows continuously for 6 hours every second , in a minimized state.
      Can you please help.
      Attached :
      1. AuInfo summary
      2. Code
      3. Simple Spy Summary
      The Actions I am trying to do (in a Minimzed State - not affecting usage of computer for other purposes)
      1. Fetch all Rows (number of rows will not always be constant
      2. Press the Check box for a specific row(s)
      3. Press the squareOff button on top
      Thanks a lot
      #include <MsgBoxConstants.au3> #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) Local $oP8=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=MO Trader;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app.0.3e799b_r8_ad1", $treescope_children) _UIA_Action($oP8,"setfocus") Local $oP7=_UIA_getObjectByFindAll($oP8, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.3e799b_r8_ad1", $treescope_children) _UIA_Action($oP7,"setfocus") Local $oP6=_UIA_getObjectByFindAll($oP7, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.3e799b_r8_ad1", $treescope_children) _UIA_Action($oP6,"setfocus") Local $oP5=_UIA_getObjectByFindAll($oP6, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.3e799b_r8_ad1", $treescope_children) _UIA_Action($oP5,"setfocus") Local $oP4=_UIA_getObjectByFindAll($oP5, "Title:=Day Net Position;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.3e799b_r8_ad1", $treescope_children) _UIA_Action($oP4,"setfocus") Local $oP3=_UIA_getObjectByFindAll($oP4, "Title:=;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.3e799b_r8_ad1", $treescope_children) _UIA_Action($oP3,"setfocus") Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=0.0000;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.Window.8.app.0.3e799b_r8_ad1", $treescope_children) _UIA_Action($oP2,"setfocus") Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=0.0000;controltype:=UIA_TableControlTypeId;class:=WindowsForms10.Window.8.app.0.3e799b_r8_ad1", $treescope_children) _UIA_Action($oP1,"setfocus") Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Data Panel;controltype:=UIA_CustomControlTypeId;class:=", $treescope_children) ;~ First find the object in the parent before you can do something Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=Row 12;ControlType:=UIA_CustomControlTypeId", $treescope_subtree) _UIA_action($oUIElement,"click") Local $string = _UIA_action($oUIElement,"getValue") MsgBox($MB_OK,"", $string) Local $oUIElement2=_UIA_getObjectByFindAll($oP0, "title:=Row 6;ControlType:=UIA_CustomControlTypeId", $treescope_subtree) _UIA_action($oUIElement2,"click") Local $string2 = _UIA_action($oUIElement2,"getValue") MsgBox($MB_OK,"", $string2)  

      SimpleSpy Row.txt
    • By ptrex
      WHAT : is .NET Common Language Runtime (CLR) Framework
      The Common Language Runtime (CLR) is a an Execution Environment . Common Language Runtime (CLR)'s main tasks are to convert the .NET Managed Code to native code, manage running code like a Virtual Machine, and also controls the interaction with the Operating System.
      As part of Microsoft's .NET Framework, the Common Language Runtime (CLR) is managing the execution of programs written in any of several supported languages. Allowing them to share common object-oriented classes written in any of the languages.
      HOW : To access the CLR environment you need to create an Appdomain Object - _CLR_GetDefaultDomain()
      An AppDomain provides an isolated region in which code runs inside of an existing process.
      Application domains provide an isolation boundary for security, reliability, and versioning, and for unloading assemblies. Application domains are typically created by runtime hosts, which are responsible for bootstrapping the common language runtime before an application is run.
      WHEN : Would you use CLR Runtime Hosts
        1. To access  .NET Class Libraries :
      System System.Collections System.Data System.Drawing System.IO System.Text System.Threading System.Timers System.Web System.Web.Services System.Windows.Forms System.Xml   2. Accessing custom build .Net Assemblies :
        Some Examples (but there are a ton out there)
      AutoItX3 - The .NET Assembly for using AutoItX JSonToXML libr. XMLRPC Libr. .NETPDF libr. .NETOCR Libr WInSCP Libr.  ...   3. To Compile .Net Code into an Assembly
        4. To Run C# or VB.net Code
        5. To Mix AU3 and .Net functionality in your Application
      WHERE :  To find documentation about CLR
      First of all you can find a lot on MSDN and here  : Post 4 & Post 6
      EXAMPLES : Multiple examples included in Zip !!
      Example : “System.Text.UTF8Encoding”

      Example : “System.IO.FileInfo”

      Example : “System.Windows.Forms”

      Example : AutoItX3 Custom .NET Assembly AutoItX

      Example : Compile Code C# and Code VB

      Example : Compile Code C# at Runtime

      WHO : Created the CLR.au3 UDF
      All credits go to : Danyfirex / Larsj / Trancexx  / Junkew
      TO DO : The library is still Work in Process …
      (Some of the GUI Controls are not yet working as expected...)
      Anyone is free to participate in contributing to get the bugs resolved and to expand the CLR.au3 functionality ...
      Enjoy !!
      DOWNLOADS :  (Last updated) 
      - added CLR Constants.au3 - Danyfirex
          - Global Constants added (Magic numbers)
      - added .NET CLR CreateObject vs ObjCreate Example.au3 - Junkew
               • 2 approaches give the same result (only valid for COM Visible Assembly)
               • Includes a function that shows you which Assembly Classes are COM Visible
      - added .Net Conventional COM Objects Examples - ptrex
      - added .NET CLR CreateComInstanceFrom Example - Danyfirex
          - You can use it for Regfree COM Assembly Access
          - System.Activator has 4 methods :
              • CreateComInstanceFrom : Used to create instances of COM objects.
              • CreateInstanceFrom : Used to create a reference to an object from a particular assembly and type name.
              • GetObject : Used when marshaling objects.
              • CreateInstance : Used to create local or remote instances of an object.
      - added .NET Access SafeArrays Using AccVarsUtilities Example - LarsJ
      - added SafeArray Utilities functions in Includes - LarsJ 
      - added .NET Access Native MSCorLib Classes - System - ptrex
          Multiple System Class Examples :
               • System.Random
               •  System.DateTime
               •  System.Diagnostics.PerformanceCounter
               •  System.IO.FileInfo
               •  System.Int32
               •  System.Double
               •  System.Speech
               • System.Web
      - added Third Party Assembly Access - ptrex
               • WinSCP : https://winscp.net/eng/download.php
               • IonicZip : http://dotnetzip.codeplex.com/
      - added more Examples using PowerShell GUI Assembly Access - ptrex 
               •  GUI Ribbon .NET Assembly using &nbsp;CLR Library 
               •  GUI Report Designer .NET Assembly using &nbsp;CLR Library
               •  GUI SSRS Reporting .NET Assembly using &nbsp;CLR Library
      .NET CLR Framework for AutoIT.pdf
    • By nooneclose
      Good morning, all. I am having a very hard time figuring out why my code "breaks" every second (and every time after) iteration in the loop. 
      I am trying to automate the process of filling out a form for work. I need to find and send data to seven fields and get data from one field. 
      Here are a couple of pictures of the fields I am interacting with. The fields are on the same forum/page. (the green boxed ones)

      Here is my code so far. 
      #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;Allows for the combining of UDFs by disabling error messages. (I get error messages for "problems" that dont actually exsist) #include <AD.au3> ;Allows Active Directory functions #include <Array.au3> ;Allows special Array functions #include <Constants.au3> ;Allows constants to be used #include <Date.au3> ;Allows Date and Time functions #include <DateTimeConstants.au3> ;Allows Date and Time constant functions #include "DTC.au3" ;Allows Custom Date and Time functions #include <IE.au3> ;Allows Internet Explorer functions #include <Misc.au3> ;Allows the "is pressed" function to be used #include <MsgBoxConstants.au3> ;Allows Message box function to be used #include <OutlookEX.au3> ;Allows the Outlook functions #include <String.au3> ;Allows special string functions #include <StringConstants.au3> ;Allows String constant functions #include <Timers.au3> ;Allows timer functions ;#RequireAdmin ;Requests admin privliges before starting program ; Special UDFs for UIA automation #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <debug.au3> #include <WinAPI.au3> #include "UIAWrappers.au3" #AutoIt3Wrapper_UseX64=N ;Should be used for stuff like tagpoint having right struct etc. when running on a 64 bits os ;******************************************************************************* ; Format and send the vaild E-mail's contents ;******************************************************************************* Func SendEmailData() ConsoleWrite("Action 16: Send E-mail Data to it's proper fields" & " at line: " & @ScriptLineNumber & @CRLF) ;=============================================================================== ; Store the Elements ;=============================================================================== ; Description _UIA_setVar("oDescription","Title:=Description:;controltype:=UIA_EditControlTypeId;class:=") ; Long Description OK Button _UIA_setVar("oLongButton","Title:=Long Description;controltype:=UIA_ImageControlTypeId;class:=") _UIA_setVar("oLongOk","Title:=OK;controltype:=UIA_ButtonControlTypeId;class:=") ; Work Order Number _UIA_setVar("oWorkOrderNum","Title:=Work Order:;controltype:=UIA_EditControlTypeId;class:=") ; Location _UIA_setVar("oLocation","Title:=Location:;controltype:=UIA_EditControlTypeId;class:=") ; Work Type _UIA_setVar("oWorkType","Title:=Work Type:;controltype:=UIA_EditControlTypeId;class:=") ; Reported By Date _UIA_setVar("oDate","Title:=Reported Date:;controltype:=UIA_EditControlTypeId;class:=") ; Reported By Person _UIA_setVar("oCustomer","Title:=Reported By:;controltype:=UIA_EditControlTypeId;class:=") ; Reported By Email _UIA_setVar("oEmail","Title:=Reported By Email:;controltype:=UIA_EditControlTypeId;class:=") ; Reported By Phone _UIA_setVar("oPhone","Title:=Reported By Phone:;controltype:=UIA_EditControlTypeId;class:=") Local $WorkType = "CM" ; Send the stored data to the proper field Local $stringSplitter = ", " Local $conCateStrings = $eDescription & $stringSplitter & $eComments Local $ComStringLen = StringLen($eComments) Local $TrimedDesc = StringTrimLeft($eDescription, 1) ;=============================================================================== ; Check to see if the Description and the Long Description can be concatenated If StringLen($conCateStrings) <= 100 Then Sleep(2000) _UIA_action("oDescription","highlight") Sleep(300) _UIA_Action("oDescription","setfocus") Sleep(300) _UIA_action("oDescription","click") Sleep(500) _UIA_action("oDescription", "setvalue", $conCateStrings) _UIA_action("oDescription","highlight") ; Wipes the long description so no duplication happens $eComments = "" ;=============================================================================== ; Send the Long Description in place of the Description ElseIf $TrimedDesc = "Other" AND $ComStringLen <= 100 Then Sleep(2000) _UIA_action("oDescription","highlight") Sleep(300) _UIA_Action("oDescription","setfocus") Sleep(300) _UIA_action("oDescription","click") Sleep(500) _UIA_action("oDescription", "setvalue", $eComments) _UIA_action("oDescription","highlight") Sleep(2000) ;=============================================================================== ; Send the Long Description in place of the Description and Send the rest of it to the Long Description field ElseIf $TrimedDesc = "Other" AND $ComStringLen >= 100 Then SplitLongDesc() ; Description gets the first 100 Characters $eDescription = $FirstLine ; Long Description gets the rest $eComments = StringMid($sNewString, 101) Sleep(2000) _UIA_action("oDescription","highlight") Sleep(500) _UIA_Action("oDescription","setfocus") Sleep(500) _UIA_action("oDescription","click") Sleep(500) _UIA_action("oDescription", "setvalue", $eDescription) _UIA_action("oDescription","highlight") Sleep(2000) ;=============================================================================== ; Send the Description and some of the Long Description ElseIf StringLen($eDescription) <= 80 AND $eComments <> "" Then SplitLongDesc() ; Description gets the first 100 Characters $eDescription = $FirstLine ; Long Description gets the rest $eComments = StringMid($sNewString, 101) Sleep(2000) _UIA_action("oDescription","highlight") Sleep(300) _UIA_Action("oDescription","setfocus") Sleep(300) _UIA_action("oDescription","click") Sleep(500) _UIA_action("oDescription", "setvalue", $eDescription) _UIA_action("oDescription","highlight") Sleep(2000) ;=============================================================================== ; Send the original Description Else Sleep(2000) _UIA_action("oDescription","highlight") Sleep(300) _UIA_Action("oDescription","setfocus") Sleep(300) _UIA_action("oDescription","click") Sleep(500) _UIA_action("oDescription", "setvalue", $eDescription) _UIA_action("oDescription","highlight") Sleep(2000) EndIf ;=============================================================================== ; Click the long description button Sleep(2000) _UIA_action("oLongButton","highlight") Sleep(300) _UIA_Action("oLongButton","setfocus") Sleep(300) _UIA_action("oLongButton", "click") _UIA_action("oLongButton", "highlight") _UIA_action("oLongButton", "click") Sleep(2000) ;=============================================================================== ; Send the long description Sleep(1000) if StringLen($eComments) >= 250 Then Sleep(500) Send($eComments) Sleep(10000) ElseIf StringLen($eComments) >= 150 Then Sleep(500) Send($eComments) Sleep(6000) ElseIf StringLen($eComments) <= 10 Then Sleep(500) Send($eComments) Sleep(1500) Else Sleep(500) Send($eComments) Sleep(4000) EndIf ;=============================================================================== ; Click the ok button Sleep(2000) _UIA_action("oLongOk","highlight") Sleep(300) _UIA_Action("oLongOk","setfocus") Sleep(300) _UIA_action("oLongOk", "click") _UIA_action("oLongOk", "highlight") Sleep(2000) ;=============================================================================== ; The work order number _UIA_action("oWorkOrderNum","highlight") Sleep(300) _UIA_Action("oWorkOrderNum","setfocus") Sleep(300) _UIA_action("oWorkOrderNum", "getvalue", $WoNum) _UIA_action("oWorkOrderNum","highlight") ;MsgBox("", "Work order number", $WoNum[2]) ;=============================================================================== ; The Location field Sleep(2000) _UIA_action("oLocation","highlight") Sleep(300) _UIA_Action("oLocation","setfocus") Sleep(300) _UIA_action("oLocation", "setvalue", $eLocation) _UIA_action("oLocation","highlight") ;=============================================================================== ; The Work Type field Sleep(2000) _UIA_action("oWorkType","highlight") Sleep(300) _UIA_Action("oWorkType","setfocus") Sleep(300) _UIA_action("oWorkType", "setvalue", $WorkType) _UIA_action("oWorkType","highlight") ;=============================================================================== ; The Reported By Date Sleep(2000) _UIA_action("oDate","highlight") Sleep(300) _UIA_Action("oDate","setfocus") Sleep(300) _UIA_action("oDate", "setvalue", $eSentOn) _UIA_action("oDate","highlight") ;=============================================================================== ; The Requested by field Sleep(2000) _UIA_action("oCustomer","highlight") Sleep(300) _UIA_Action("oCustomer","setfocus") Sleep(300) _UIA_action("oCustomer", "setvalue", $eReportedBy) _UIA_action("oCustomer","highlight") ;=============================================================================== ; The Requested by E-mail Sleep(2000) _UIA_action("oEmail","highlight") Sleep(300) _UIA_Action("oEmail","setfocus") Sleep(300) _UIA_action("oEmail", "setvalue", $eSenderAddress) _UIA_action("oEmail","highlight") ;=============================================================================== ; The Requested by Phone Sleep(2000) _UIA_action("oPhone","highlight") Sleep(300) _UIA_Action("oPhone","setfocus") Sleep(300) _UIA_action("oPhone", "setvalue", $eRoomPhone) _UIA_action("oPhone","highlight") MouseClick("left", 1843, 437, 2) Sleep(1500) Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Sleep(1000) MouseClick("left", 591, 279, 2) Sleep(3000) $lCount += 1 ConsoleWrite("Action 16: Finished" & " at line: " & @ScriptLineNumber & @CRLF) Sleep(2000) EndFunc  
      That is not all the code but that is the function that keeps "breaking" and by "breaking" I mean the program acts like it doesn't know where the description field is after the first iteration.
      My code will just click somewhere in the far top left corner and somehow shrink the browser in the process of finding the description field.  
      The code works perfectly the first iteration but after that, it "breaks" (doesn't know where to click/send data to). 
      As always any help is greatly appreciated. 
      NOTE: By the time 'Action 16' runs Chrome has already been opened and has navigated to the proper webpage.  I am trying to loop 'Action 16' multiple times. I do not leave that webpage while looping. 
  • Create New...