Jump to content

Automating application with ATX controls - Trying out IUIAutomation MS Framework...


Recommended Posts

Hi all,

So I am trying to automate a few tasks at work which require me to read and write values from some forms in the HEAT ticketting system application (a help desk application which seems to predominantly use AFX controls).

I have seen in a few other threads advice to use the IUIAutomation framework (from this link: '?do=embed' frameborder='0' data-embedContent>>) for this type of job... however, this has not been easy to understand.

Basically, I need to pull text from the following types of controls:

- A node on a tree control (I need it's title text value). The AutoIT window info tool gives me the class: AfxWnd70.
- One of a number of text fields; The autoIT window info tool will not let me select an individual field. Instead, it grabs the entire pane and returns the class: AfxFrameOrView70.
 

With the spy tool from the link for the automation framework above, I get this info for the tree node:

http://pastebin.com/5qp6gSCw

...and this info for one of the text fields:

http://pastebin.com/1DwymtsF

Can anyone point me in the right direction on how I might grab (and modify) the text from these controls (the title for the tree node, and the value for any of the text boxes)? I would really appreciate any assistance anyone might be able to provide. **I have read through the examples posted under the IUIAutomation MS framework thread, but am still pretty lost...

Thank you!

Link to comment
Share on other sites

doktor, As a start can you run this code in Scite, and check if the text of the treeview nodes are printed in the console:

; Client UI Automation UDF
#include "CUIAutomation2.au3"

Opt( "MustDeclareVars", 1 )

MainFunc()

Func MainFunc()

  ; Get window handle
  Local $hWindow = WinGetHandle( "[CLASS:AfxWnd70]" )
  If Not $hWindow Then Return

  ; Create UI Automation object
  Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
  If Not IsObj( $oUIAutomation ) Then Return

  ; 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

  ; Condition to find tree item
  Local $pCondition
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TreeItemControlTypeId, $pCondition )
  If Not $pCondition Then Return

  ; Find all tree items
  Local $pElementArray, $oElementArray, $iElements
  $oWindow.FindAll( $TreeScope_Descendants, $pCondition, $pElementArray )
  $oElementArray = ObjCreateInterface( $pElementArray, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray )
  $oElementArray.Length( $iElements )
  If Not $iElements Then Return

  ; Print all tree item texts
  Local $pElement, $oElement, $sName
  For $i = 0 To $iElements - 1
    $oElementArray.GetElement( $i, $pElement )
    $oElement = ObjCreateInterface( $pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
    $oElement.GetCurrentPropertyValue( $UIA_NamePropertyId, $sName )
    ConsoleWrite( $sName & @CRLF )
  Next

EndFunc

I would like to see a picture of your program as it looks on screen. Can you create a screen dump that shows the treeview nodes and the text boxes?

Link to comment
Share on other sites

I probably shouldn't be posting this, but oh well:

EZeOhuHz.jpg

EDIT: Here is a link to the pic: http://imgbox.com/EZeOhuHz

The above link goes to the picture (it appears broken for some reason on my end). That is the application I am working in (with client data covered in red lines)... I would ideally like to get or set text in any of the fields outlined in the big green rectangle, and I also need the Call ID for this script, so I can either get it from the small green rectangle, or if you look just beside it to the right in the status bar (under the copy/paste buttons), it is listed there too.

All I really NEED is the client email and call-ID, but I'm sure if I can get those, I can manipulate most fields on the application.

Thank you!
 

Edited by doktor
Link to comment
Share on other sites

The picture is fine. Have you run the code in post #2? We need a handle to the top window. And we need to know if it's possible to find the treeview nodes and the text boxes.

Link to comment
Share on other sites

Sorry about the delayed reply; I just started this job, and the training is very time consuming.

The code in post 2 returned "0" for its exit code, but did not print anything to the console. The class "[CLASS:AfxWnd70]" (which the window info tool returned) is actually the class name of the tree control... the class name I am getting for the window is "BENDATAWINHEAT", and the title is "Call Logging - [Work Group - 3 of 3]".

I swapped in the window class given above (using the code from post #2), and still got nothing. If you check the pastebin links in my first post, I included info using the IUIAutomation framework tool - which I linked to in that post - for each of the controls I'm talking about.

If you need any more specific info, I'm all ears; I'll check back here by the end of the day.

 

Link to comment
Share on other sites

I have added some ConsoleWrite statements to the code. Then you can see where the script stops. I'm pretty sure that it's a wrong window handle. We need the window handle for the top window. If you use the AutoIt Window Info tool on the window title bar, you should get the class name for the top window.

You can also use the window title like this:

Local $hWindow = WinGetHandle( "My window title" )

This is the new code:

; Client UI Automation UDF
#include "CUIAutomation2.au3"

Opt( "MustDeclareVars", 1 )

MainFunc()

Func MainFunc()

  ; Section 1
  ; Get window handle
  Local $hWindow = WinGetHandle( "[CLASS:AfxWnd70]" )
  If Not $hWindow Then
    ConsoleWrite( "Window handle ERROR" & @CRLF )
    Return
  Else
    ConsoleWrite( "Window handle OK" & @CRLF )
  EndIf

  ; Section 2
  ; Create UI Automation object
  Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
  If Not IsObj( $oUIAutomation ) Then
    ConsoleWrite( "UI Automation object ERROR" & @CRLF )
    Return
  Else
    ConsoleWrite( "UI Automation object OK" & @CRLF )
  EndIf

  ; Section 3
  ; 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
    ConsoleWrite( "UI Automation element ERROR" & @CRLF )
    Return
  Else
    ConsoleWrite( "UI Automation element OK" & @CRLF )
  EndIf

  ; Section 4
  ; Condition to find tree item
  Local $pCondition
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TreeItemControlTypeId, $pCondition )
  If Not $pCondition Then
    ConsoleWrite( "Condition ERROR" & @CRLF )
    Return
  Else
    ConsoleWrite( "Condition OK" & @CRLF )
  EndIf

  ; Section 5
  ; Find all tree items
  Local $pElementArray, $oElementArray, $iElements
  $oWindow.FindAll( $TreeScope_Descendants, $pCondition, $pElementArray )
  $oElementArray = ObjCreateInterface( $pElementArray, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray )
  $oElementArray.Length( $iElements )
  If Not $iElements Then
    ConsoleWrite( "Find ERROR" & @CRLF )
    Return
  Else
    ConsoleWrite( "Find OK" & @CRLF )
  EndIf

  ; Section 6
  ; Print all tree item texts
  Local $pElement, $oElement, $sName
  For $i = 0 To $iElements - 1
    $oElementArray.GetElement( $i, $pElement )
    $oElement = ObjCreateInterface( $pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
    $oElement.GetCurrentPropertyValue( $UIA_NamePropertyId, $sName )
    ConsoleWrite( $sName & @CRLF )
  Next

EndFunc

When you run the code, it should show that the window handle in section 1 is OK.

To get the UI Automation element in section 3 we need the window handle.

We are trying to find tree view items in section 4 ($UIA_TreeItemControlTypeId), because line 4 in the first spy info attachment in first post shows that the window contains tree view items.

When you run the script the screen should look like the picture in post #3.

If your application is running as a 64 bit program, you should run the script as a 64 bit program.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...