Jump to content

ControlClick Help


Go to solution Solved by Bowmore,

Recommended Posts

Hello,

I am a newbie to Autoit. As a QA Analyst I was attracted to Autoit to write some automation scrips for regression testing, but I am having some difficulty with the "ControlClick" command.

I am wondering if I am having issues with this command because I am not using the full window name "Order Tracking Main "Event Tracking" Screen", but I was trying to stay away from that because the name itself has double quotes in it...

Any help/advice is appreciated!

Here is what i have coded:

ControlClick("Order Tracking Main", "WindowsForms10.BUTTON.app.0.143a722_r15_ad11", "btnNewOrder")

And here is the Autoit Window Info Summary of "New Order" button"

>>>> Window <<<<

Title: Order Tracking Main "Event Tracking" Screen

Class: WindowsForms10.window.8.app.0.143a722_r15_ad1

Position: 338, 53

Size: 1435, 1004

Style: 0x16CF0000

ExStyle: 0x00050100

Handle: 0x00470834

>>>> Control <<<<

Class: WindowsForms10.BUTTON.app.0.143a722_r15_ad1

Instance: 1

ClassnameNN: WindowsForms10.BUTTON.app.0.143a722_r15_ad11

Name: btnNewOrder

Advanced (Class): [NAME:btnNewOrder]

ID: 4457834

Text: New Order

Position: 282, 6

Size: 57, 40

ControlClick Coords: 30, 20

Style: 0x5601000B

ExStyle: 0x00000000

Handle: 0x0044056A

Link to comment
Share on other sites

Hi,

Welcome to the autoit forum :)

Here is the right syntax :

ControlClick("[TITLE:Order Tracking Main;CLASS:WindowsForms10.window.8.app.0.143a722_r15_ad1]", "", "[CLASS:WindowsForms10.BUTTON.app.0.143a722_r15_ad1; INSTANCE:1]")

I suggest you to read the help file for this function if it's not already done. In particular this.

If you have any questions concerning the syntax please ask ;)

Edit: You should use the AutoIt3Info tool included in the autoit setup package which is designed to be used with the autoit functions.

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

Welcome to AutoIt and the forum!

Windows Forms Controls seem hard (if even possible) to automate. Please search the forum for "ControlClick WindowsForms" and you will find a few threads on this subject.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I use [REGEXPCLASS:] to grab those types of control. Works well...such as [REGEXPCLASS:.*BUTTON.*]

I think the appended string is dynamic, so shouldn't be hard coded (could be wrong)

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Thank you all for the replies. I was unable to get this to work so I just used the below code. I know its not as elegant of a solution, but it works for me :)

Eventually i will go back and try to get this to work the way I wanted, but due to time constraints, i had to take the easy way out :P

MouseClick("left", 650, 120, 1, 0) ;Click "New Order" button
Link to comment
Share on other sites

Ok, i figured out why the code that Firefox provided was not working for me.

I was doing the "ControlClick" command right after i launched the program with the "Run" command. I figured out that at that time, "Program Manager" is/was the active window, so i used "WinActivate" to make said program the active window and then the "ControlClick" command worked.

here is the code:

Run("C:\Program Files (x86)\EventTracking.exe") ;Run Order Tracking

sleep(500) ;Wait for screen to load

WinActivate("[TITLE:Order Tracking Main]", "") ;Make sure Order Tracking Main is the active window
$activeWindowTitle = WinGetTitle("[active]") ;Get the title of the active window and store it for future use
ControlClick($activeWindowTitle, "", "[CLASS:WindowsForms10.BUTTON.app.0.143a722_r15_ad1; INSTANCE:1]")
Link to comment
Share on other sites

even better is the "WinWaitActive" command.

(sorry for all the posts, but I figured it might help other noobs)

Run("C:\Program Files (x86)\EventTracking.exe") ;Run Order Tracking

WinWaitActive("[TITLE:Order Tracking Main]", "") ;Wait until "Order Tracking Main" is the active window

ControlClick(WinGetTitle("[active]"), "", "[CLASS:WindowsForms10.BUTTON.app.0.143a722_r15_ad1; INSTANCE:1]")
Edited by Shrapnel
Link to comment
Share on other sites

you can also use controlistview......For example

$COMPANY_NAME="Filename.exe"
$ControlID1 = ControlListView("Network Connections", "", "SysListView321", "FindItem", $COMPANY_NAME, "AACABLE - DIALER SERVICE");creat an id
ControlListView("Network Connections", "", "SysListView321", "Select", $ControlID1);Select some thing witch name is equal $COMPANY_NAME
send("{enter}")

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Link to comment
Share on other sites

even better is the "WinWaitActive" command.

(sorry for all the posts, but I figured it might help other noobs)

Run("C:\Program Files (x86)\EventTracking.exe") ;Run Order Tracking

WinWaitActive("[TITLE:Order Tracking Main]", "") ;Wait until "Order Tracking Main" is the active window

ControlClick(WinGetTitle("[active]"), "", "[CLASS:WindowsForms10.BUTTON.app.0.143a722_r15_ad1; INSTANCE:1]")

I've found using this is a little more failsafe:

RunWait("C:\Program Files (x86)\EventTracking.exe") ;Run Order Tracking
ControlClick(WinGetTitle("[active]"), "", "[CLASS:WindowsForms10.BUTTON.app.0.143a722_r15_ad1; INSTANCE:1]")
Link to comment
Share on other sites

How is using RunWait a better option? It will pause the script until you exit the program you started, so when does the ControlClick get activated?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Solution

As the debeveloper have been kind and given a name to the control this should provide a reliable method of identifying the button in AutoIt.

ControlClick("Order Tracking Main", "", "[NAME:btnNewOrder]")

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

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