Jump to content

Find Classes by Text (v1.2)


LxP
 Share

Recommended Posts

Sometimes it can be difficult to automate some software for one of a few reasons:

  • Perhaps different fields share a common control ID.
  • Perhaps the GUI designer overlapped many controls, so AutoIt Window Info won't show you the one that you actually have your mouse over.

This script aims to provide a solution. The idea is for you to populate such a GUI with different values in each field, and then allow this script to 'capture' that window. It will then group controls sharing the same text values and display their ClassNameNNs, which is generally** an excellent way to reliably differentiate between controls.
 

Download: FindClassesByText.au3

Operation:

  • Prepare the window that you wish to automate.
  • Start this script.
  • Click the Capture button.
  • Activate the other window by clicking on it.
  • Return to the script's window and browse the assembled TreeView.

** Proven not to work with .NET applications; _ControlGetHandleByPos() may be your only hope there.

v1.2 (29/May/2013):
  • Add "Copy Item" and "Copy All" buttons to copy information from the TreeView to the clipboard (thanks to the idea)
  • Show control text as an AutoIt string definition (with macros as appropriate) instead of just naively wrapping it in single quotes
v1.1 (27/May/2013):
  • Adjust for script-breaking changes in AutoIt v3.2.12.0 (thanks to )
v1.0 (4/Mar/2006):
  • Initial release
Edited by LxP
Link to comment
Share on other sites

  • Moderators

Great work, this will be very useful. Now I see how you were able to figure out the ClassNameNNs of that Trackit Audit program I had.

It would be nice to have the ability to copy the ClassNameNNs, or possibly a double click to send to SciTE.

Edited by big_daddy
Link to comment
Share on other sites

Great work, this will be very useful. Now I see how you were able to figure out the ClassNameNNs of that Trackit Audit program I had.

Thanks! I wish I had this script around when I helped you out. :o

It would be nice to have the ability to copy the ClassNameNNs, or possibly a double click to send to SciTE.

Yes; I agree. I didn't spend too long looking at how I could make a TreeView item interactive. I'll look at that the next time I work with AutoIt.
Link to comment
Share on other sites

LXP, the script you made is awesome! I have tried it on a bunch of windows and it works lovely! Thanks for taking the time to do that!

However, sadly, for the problematic ACT! Build 6.0.0.679 Window, I still cannot get even your script to bring me the solution. As of right now, there is no way to capture the info that your awesome script returned (like copy/paste), so I cannot show you ALL of what I got back. But I will describe what info your script gave me so you can help us figure out what is going on.

I will add the info/problem in the our previous post, so we don't bog down your post here (the link below)

Post

Thanks again LXP! The script works for all of my other windows!

Link to comment
Share on other sites

I hope you don't mind, but I added a copy feature to your script.

I don't mind at all! I like your addition very much; transcribing window information otherwise is definitely not fun.

Ideally, I suppose there would be a button that copies all information to the clipboard in a format similar to this perhaps:

'Text contained in control with special characters substituted out'
   ClassNameNN
   ClassNameNN
   ClassNameNN
'Text contained in control with special characters substituted out'
   ClassNameNN
   ClassNameNN
   ClassNameNN
'Etc.'
   Etc
   Etc
   Etc

...but I don't see myself doing this in the near future.

Link to comment
Share on other sites

I did a messagebox to get the individual lines in a paragraph. Not the ideal method, as you describe, but it works until a more suitable method is adopted as you describe, LxP.

Mostly changes to the last func. I did change the size of the Gui to something alittle smaller though. :geek:

ctrlbypos.au3

Much nicer with the Copy functions added in. Saves on manually labour. :o

Link to comment
Share on other sites

It isn't the prettiest thing in the world, but she works. If a single ClassNameNN is selected it will copy only that one item to the clipboard. If a parent item is selected then it will copy all of it's child items to the clipboard.

FindClassesByText.au3

This script is wonderful.

Since I do not know how to do this, I have to ask for help. Is it possible to make a 'Copy All' feature? In that, I would like to test EVERY control on the window to trouble shoot my controls. In that, when I can't find a ControlID/ClassNameNN, it would be great to paste it into Scite, then run my script for every control. I know that would mean like 300 items, but as a last resort, when all else fails, it would be great to have.

THanks.

Link to comment
Share on other sites

Is it possible to make a 'Copy All' feature? In that, I would like to test EVERY control on the window to trouble shoot my controls. In that, when I can't find a ControlID/ClassNameNN, it would be great to paste it into Scite, then run my script for every control. I know that would mean like 300 items, but as a last resort, when all else fails, it would be great to have.

The original script contains a function called WinGetControlIDs() which prepares a list of all ClassNameNNs for a window. You can use it in this fashion:

Local $ID, $ClassNameNNs = WinGetControlIDs('Window title', 'Window text')
For $I = 1 To $ClassNameNNs[0]
    $ID = $ClassNameNNs[$I]
   ; (and then perform some action where $ID will contain one particular ClassNameNN)
Next

...to perform some task on every single control.

Link to comment
Share on other sites

The original script contains a function called WinGetControlIDs() which prepares a list of all ClassNameNNs for a window. You can use it in this fashion:

Local $ID, $ClassNameNNs = WinGetControlIDs('Window title', 'Window text')
For $I = 1 To $ClassNameNNs[0]
    $ID = $ClassNameNNs[$I]
  ; (and then perform some action where $ID will contain one particular ClassNameNN)
Next

...to perform some task on every single control.

I understand a little bit, but be patient as I am still young in my programming knowledge.

So for example, would this be correct?

Local $ID, $ClassNameNNs = WinGetControlIDs('Window title', 'Window text')
For $I = 1 To $ClassNameNNs[0]
    $ID = $ClassNameNNs[$I]
  ControlCommand ("Eudora", "", $ID, "ShowDropDown", "")
Next

Oh, and could you help a noob out and tell me what "[$I]", and "[0]" does? Or where to read more about it?

Thanks!

Link to comment
Share on other sites

  • Moderators

I understand a little bit, but be patient as I am still young in my programming knowledge.

So for example, would this be correct?

Local $ID, $ClassNameNNs = WinGetControlIDs('Window title', 'Window text')
For $I = 1 To $ClassNameNNs[0]
    $ID = $ClassNameNNs[$I]
  ControlCommand ("Eudora", "", $ID, "ShowDropDown", "")
Next

Oh, and could you help a noob out and tell me what "[$I]", and "[0]" does? Or where to read more about it?

Thanks!

Hmmm...

I would take a "gander" at Array and For/Next Loop in the help file.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

So for example, would this be correct?

Local $ID, $ClassNameNNs = WinGetControlIDs('Window title', 'Window text')
For $I = 1 To $ClassNameNNs[0]
    $ID = $ClassNameNNs[$I]
  ControlCommand ("Eudora", "", $ID, "ShowDropDown", "")
Next
Almost. You need to appropriately set the 'Window title' and 'Window text' placeholders in the first line (the 'Window text' one can be removed if not needed).

This code will run the ShowDropDown command on every control of the Eudora window:

Local $ID, $ClassNameNNs = WinGetControlIDs('Eudora')
For $I = 1 To $ClassNameNNs[0]
    $ID = $ClassNameNNs[$I]
    ControlCommand('Eudora', '', $ID, 'ShowDropDown')
Next

It will also do it rather fast, so you may not see much. Perhaps you'd like to add a Sleep(500) between the ControlCommand() line and Next to pause for half a second between each attempt.

WinGetControlIDs() returns an array, which is one variable capable of holding multiple values at once. These multiple values are known as elements of the array. If $Array were an array with 5 elements, you could access these elements as $Array[0] to $Array[4].

You are not limited to entering a literal number between the square brackets to access a certain element. If you have some number in another variable you can use that variable to determine which element is accessed, e.g. --

; Declare an array of 5 elements
Local $Array[5]
; Declare a variable with a number
Local $Num = 2
; Set element 2 (the third element) of $Array
$Array[$Num] = 'Ding!'

You can use the For..Next construct to run through each element of an array. You first need to determine how many times to run the loop, in this case how many useful elements there are in the array.

WinGetControlIDs() (along with a few other AutoIt-native functions returning an array) uses element 0 specially -- it contains a count of the remaining elements. By programming a loop to run from 1 to that count, we can access each element of that array in turn. This is what is being done above.

(Hopefully I'll remember this post when I next work on my tutorial...)

Link to comment
Share on other sites

  • 1 year later...

not to bump an old post but does this still work... or is there alternate more updated methods to attempt to obtain controlID's? running the script seems to spit back info into the gui when focusing on normal windows (that also return data in the window info tool) however comes up with nothing on the windows that don't give anything in the win info tool either >.<

specificly - trying to get control id info for a World of warcraft window - by fluke or miracle i can controlsend keystrokes to it but controlclick won't work with the same logic - i assume because there are no controlclick cords in the win info tool :D

Don't let that status fool you, I am no advanced memeber!

Link to comment
Share on other sites

  • 5 months later...

Hi,

many thanks for the script, clicking "Copy to clipboard" returns

C:\Program Files\AutoIt3\Include\FindClassesByText.au3 (327) : ==> Subscript used with non-Array variable.:

If StringInStr($a_Item[0], "'") <> 0 Then

If StringInStr($a_Item^ ERROR

Is this still supported? Would be useful to have.

Link to comment
Share on other sites

Hi,

many thanks for the script, clicking "Copy to clipboard" returns

C:\Program Files\AutoIt3\Include\FindClassesByText.au3 (327) : ==> Subscript used with non-Array variable.:

If StringInStr($a_Item[0], "'") <> 0 Then

If StringInStr($a_Item^ ERROR

Is this still supported? Would be useful to have.

I'm not at all sure about this quick change but it seems to work if you want to copy the class name selected in the treeview.

; ==============================================================================
; CopyTreeViewItem():
;    Copies the selected TreeViewItem to the clipboard.
; ==============================================================================

Func CopyTreeViewItem()
    
    Local $a_Item[2]
$a_Item[0] = GUICtrlRead($Handles[$HAN_TREE], 1);text
$a_Item[1] = GUICtrlRead($Handles[$HAN_TREE]);id
    ConsoleWrite($a_Item & @CRLF)
    Local $a_NextItem
    Local $a_FirstChild
    Local $a_Child[2]
    Local $a_Check
    Dim $avArray[1]
    If Not @error then;and isarray($a_Item) Then
    ; Check to see if it is a parent item
        If StringInStr($a_Item[0], "'") <> 0 Then;[0]
        ; Get first child of selected TreeViewItem
            $a_FirstChild = GUICtrlSendMsg($Handles[$HAN_TREE], $TVM_GETNEXTITEM, _
            $TVGN_CHILD, GUICtrlGetHandle($a_Item[1])) 
        ; Select the first child item
            GUICtrlSendMsg($Handles[$HAN_TREE], $TVM_SELECTITEM, $TVGN_CARET, _
            $a_FirstChild) 
            While 1
            ; Read selected item
                $a_Child[1] = GUICtrlRead($Handles[$HAN_TREE], 1)
                $a_Child[0] =  GUICtrlRead($Handles[$HAN_TREE])
            ; This is ugly, please help me revise!
                If $a_Check == 0 Then ExitLoop
            ; Insert selected child text into array
                $avArray[UBound($avArray) - 1] = $a_Child[0]
                ReDim $avArray[UBound($avArray) + 1]
            ; Get the control id of the next child
                $a_NextItem = GUICtrlSendMsg($Handles[$HAN_TREE], $TVM_GETNEXTITEM, _
                $TVGN_NEXT, GUICtrlGetHandle($a_Child[1]))
            ; Select the next child
                GUICtrlSendMsg($Handles[$HAN_TREE], $TVM_SELECTITEM, $TVGN_CARET, _
                $a_NextItem)
            ; This is also ugly!
                $a_Check = $a_NextItem
            WEnd
            _ArrayToClip($avArray)
        Else
            ClipPut($a_Item[0])
        EndIf
    EndIf
    
EndFunc  ;==>CopyTreeViewItem
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 5 months later...

Does this script still work? I tried it and I get an error about $GUI_SS_DEFAULT_GUI not being declared.

+>13:58:13 Starting AutoIt3Wrapper v.1.10.1.14  Environment(Language:0409  Keyboard:00000409  OS:WIN_XP/Service Pack 2  CPU:X86  ANSI)
>Running AU3Check (1.54.13.0)  from:C:\Program Files\AutoIt3
C:\autoitscripts\FindClassesByText.au3(63,29) : WARNING: $GUI_SS_DEFAULT_GUI: possibly used before declaration.
            BitOR($GUI_SS_DEFAULT_GUI,
            ~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\autoitscripts\FindClassesByText.au3(63,42) : WARNING: $WS_SIZEBOX: possibly used before declaration.
            BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX,
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\autoitscripts\FindClassesByText.au3(63,59) : WARNING: $WS_MAXIMIZEBOX: possibly used before declaration.
            BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_MAXIMIZEBOX)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\autoitscripts\FindClassesByText.au3(68,53) : WARNING: $BS_MULTILINE: possibly used before declaration.
            Default, Default, Default, Default, $BS_MULTILINE)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\autoitscripts\FindClassesByText.au3(101,47) : WARNING: $WS_EX_CLIENTEDGE: possibly used before declaration.
            $GUI_SS_DEFAULT_TREEVIEW, $WS_EX_CLIENTEDGE)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\autoitscripts\FindClassesByText.au3(63,29) : ERROR: $GUI_SS_DEFAULT_GUI: undeclared global variable.
            BitOR($GUI_SS_DEFAULT_GUI,
            ~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\autoitscripts\FindClassesByText.au3 - 1 error(s), 5 warning(s)

Any ideas how to get the script to work, downgrade my version of auto it?

Edited by oldguy
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...