Jump to content

Need help with GUI Automation


 Share

Recommended Posts

Hi,

I need some help to get started with AutoIT. I'm looking to develop a script that would automate a Win32 app.

I want it to retrieve specific subitems from ListViews, close tabs, click on ListView's headers, etc.

I looked for a tutorial, but each time I found only ones that taught me how to create a GUI that had those elements

(ListViews, tabs, etc).

Can you point me out some quick start tutorials for GUI Automation with AutoIT?

The one that shows how to start the Notepad, is not enough.

I need something that covers areas like, handlers, messages, notifications, etc.

For example, in Perl, I found this tutorial as a starting point http://www.piotrkaluski.com/files/winguitest/docs/ch02s04.html

and I've written a few scripts, but I hit a dead end with sending a LVN_COLUMNCLICK notification under Win7 x64.

I could not make it work at all, even though it worked fine under WinXP x86 and x64.

So, I've decided that I have to try something else, too.

Link to comment
Share on other sites

Welcome to the Forum!

I would suggest looking at the Help File for >> ControlCommand() (you might have done this from what you said) & then Search the Forum using ControlCommand() as the keyword, there are a lot of Examples. Trust me :)

I never use AutoIt for Automtaion but ControlGetHandle() might help and ControlGetText() too. Good Luck!

Plus, ControlListView() might be of some use.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

As guinness suggested, the helpfile is an excellent place to learn what you need to know. If you go to the contents, you'll see a folder named "Window Management". That contains a sub-folder named "Controls". Pretty much everything you've asked about is covered by a function within that folder. Additionally, you can use the AutoIt Window Info tool to figure out what type of controls are on any given Win32 application, as well as information you can use to identify and target those controls (assuming they are standard WinAPI controls).

Link to comment
Share on other sites

Thank you, guys.

I've managed to get things started.

..but I've stopped here:

$return=_GUICtrlToolbar_ClickButton($hWnd, $iCommandID)

$return=_GUICtrlToolbar_ClickIndex($hWnd, $iIndex)

Neither of these commands does click on a specific button from a ToolbarWindow32 pointed by $hWnd.

For $iIndex and $iCommandID identification I used KaFu's script:

Any ideas?

Link to comment
Share on other sites

  • Moderators

Thank you, guys.

I've managed to get things started.

..but I've stopped here:

$return=_GUICtrlToolbar_ClickButton($hWnd, $iCommandID)

$return=_GUICtrlToolbar_ClickIndex($hWnd, $iIndex)

Neither of these commands does click on a specific button from a ToolbarWindow32 pointed by $hWnd.

For $iIndex and $iCommandID identification I used KaFu's script:

Any ideas?

You ask "Any Ideas", yet so many specifics are left out, specifically what app you're trying to automate ( not as important though as some type of actual runnable/recreation code ).

Here's an "educated guess". Your $hWnd is either A.) Not a handle or B.) Not the handle to the toolbar ( eg. the param explanation: Handle to the control ).

More interesting than not though, is how this skipped from a listview issue to a toolbar one.

Edited by SmOke_N

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

In order to have a listview, I have to press some buttons, and fill some fields.

I'll get to the listview, too.

Here's the code, I've tried it on 3 different apps that contained ToolbarWindow32 resources. I've pasted the handle manually. You can try it on WordPad(didn't work for me), if there are no mistakes in my code.

Btw, I need a function like FindWindowEx, is there a similar thing in AutoIT?

I need to work with handles, children windows, parent windows, controlID's, etc because there are many windows that have the same title.

#include <GUIConstantsEx.au3>
#Include <GuiToolBar.au3>
Opt('MustDeclareVars', 1)

Example()

Func Example()
dim $hWnd=HWnd(0x003D09C2)
dim $iIndex=1
dim $return=_GUICtrlToolbar_ClickIndex($hWnd, $iIndex)
MsgBox(4096, "return is", $return)
EndFunc
Edited by Expansion
Link to comment
Share on other sites

  • Moderators

Btw, I need a function like FindWindowEx, is there a similar thing in AutoIT?

I need to work with handles, children windows, parent windows, controlID's, etc because there are many windows that have the same title.

WinGetHandle()

ControlGetHandle()

?

Edit:

I'm using Win7 since I assume that's where you had problems.

Opening WordPad, I don't see where it has ToolbarWindow32 ( I see a ribbon type control )?

Edited by SmOke_N

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

The idea is to be able to search for child windows, when you specify the handle for the parent window.

Can I do that with those functions?

I'm asking because help shows the following:

WinGetHandle ( "title" [, "text"] )

ControlGetHandle ( "title", "text", controlID )

LE: It seems that I can specify handles as titles, so, yes these are what I was looking for.

Thank you.

Btw, I've tried this code for sorting a listview according to a header column, but it did not work, either.

#Include <GuiListView.au3>

Example()

Func Example()
$hWnd=0x000608D8
$iCol=2
_GUICtrlListView_SortItems($hWnd, $iCol)
EndFunc

I forgot to mention that I am working in a VM at the moment, in WinXP x86, and WordPad has ToolbarWindow32 resources.

New, Save, Print, etc.

Edited by Expansion
Link to comment
Share on other sites

  • Moderators

Expansion,

From the Help file page for _GUICtrlListView_SortItems:

"For use only in conjunction with _GUICtrlListView_RegisterSortCallBack"

Did you use that function in your script? :)

M23

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

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I've tried this, and it did not work:

#Include <GuiListView.au3>

Example()

Func Example()
$hWnd=0x000608D8
$iCol=2
_GUICtrlListView_RegisterSortCallBack($hWnd)
_GUICtrlListView_SortItems($hWnd, $iCol)
_GUICtrlListView_UnRegisterSortCallBack($hWnd)
EndFunc
Link to comment
Share on other sites

  • Moderators

I used Win 7's Explorer ( first thing I saw with a toolbarwindow32 ).

If you open up an explorers window in Win 7, and go to the libraries dir, the below worked for me.

#include <GUIConstantsEx.au3>
#include <GUIToolbar.au3>

; Open an explorer window in the in the libraries dir
Global $gh_wnd = WinGetHandle("[CLASS:CabinetWClass;TITLE:Libraries]")

If Not $gh_wnd Then
    MsgBox(16 + 262144, "Error", "Window does not exist")
    Exit
EndIf

WinActivate($gh_wnd)

; A pause so you can see it happen
Sleep(2000)

Global $gh_toolbar_url = ControlGetHandle($gh_wnd, "", "[CLASS:ToolbarWindow32; INSTANCE:2]")
If Not $gh_toolbar_url Then
    MsgBox(16 + 262144, "Error", "Toolbar does not exist")
    Exit
EndIf

_GUICtrlToolbar_ClickIndex($gh_toolbar_url, 0)

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

  • Moderators

I've tried this, and it did not work:

#Include <GuiListView.au3>

Example()

Func Example()
$hWnd=0x000608D8
$iCol=2
_GUICtrlListView_RegisterSortCallBack($hWnd)
_GUICtrlListView_SortItems($hWnd, $iCol)
_GUICtrlListView_UnRegisterSortCallBack($hWnd)
EndFunc

Remember these control functions take the "Controls" ( Child Window ) handle, not the parent.

Also, you're passing an integer not an hwnd, I'm not 100% sure if that affects it, but I'm always careful to pass what is required.

Edited by SmOke_N

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

There is a SysListView32, that has a SysHeader32 that has a number of columns/items.

I want to sort the listview according to one of those columns. Which handle should I use for _GUICtrlListView_SortItems($hWnd, $iCol) ?

The handle of the SysListView or the handle of the SysHeader?

I can't get any information about the header's items using Window Info.

Link to comment
Share on other sites

With this code and the handle for the listview:

#Include <GuiListView.au3>

Example()

Func Example()
$hWnd=HWnd(0x000608D8)
$iCol=1
_GUICtrlListView_RegisterSortCallBack($hWnd)
_GUICtrlListView_SortItems($hWnd, $iCol)
_GUICtrlListView_UnRegisterSortCallBack($hWnd)
EndFunc

This is what it happens[instead of sorting by Size, it shows that greyed arrow, and it keeps the Filename arrow]:

post-62895-0-49683000-1297600691_thumb.p

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