Rahul k
Rahul k

Reputation: 37

Unable to find control

I want to find and click a button using Autoit. I tried AutoIt Window Information Tool but the button is not recognized so ControlClick() fails.

The button is active on the current window but Send("Enter") does not work. Tried using MouseClick() but the window does not appear in the same place every time, and I tried this script:

$hWnd = WinWait("vcredist_x86")
WinWaitActive("vcredist_x86")
ControlClick($hWnd, "", "[CLASS FROM AUTOITINFO]", "Left", 1)

but neither of them works. Is there any other way to identify and click the button?

Upvotes: 0

Views: 3696

Answers (2)

garbb
garbb

Reputation: 679

When AutoIt Window Information Tool failed me I had success using the text property of the button/ui control:

ControlClick($hwin, '', '[CLASS:Button; TEXT:Cancel]')

Experiment with "&" in front of one of the characters (underlined by Windows to indicate an Alt + key shortcut), so try "&Cancel" instead of "Cancel". If that fails try ControlFocus() first:

ControlFocus($hwin, '', '[CLASS:Button; TEXT:Cancel]')
ControlClick($hwin, '', '[CLASS:Button; TEXT:Cancel]')

Inspecting .exe files for GUI resources (using Resource Hacker for example) may expose text/properties of a control. Example:

enter image description here

Upvotes: 0

Milos
Milos

Reputation: 2946

If both version of AutoItWindowInfo(32 and 64bit) don't "see" the control you need to automate, here is what you can do:

Method 1 - Sending keystrokes:

  1. Activate the window with WindowActivate
  2. Send a number of TABs until the control is focused(if its not initially)
  3. Send ENTER or SPACE

Method 2 - MouseClick:

  1. Activate the window
  2. Get the coordinates of a control relative to the application window(position the window at 0,0. Open Autoit Window Info, click on Mouse tab and get the position of the button). That position is usually always the same
  3. When your code is running it must get the window position with WinGetPos and then add control position you got in step 2. That's your clicking position.

Method 3 - PixelSearch(If the control has unique color):

  1. Get the desired color with AutoIt Window Info(mouse tab)
  2. Search it using PixelSearch
  3. Click the coords you got

Method 4 - ImageSearch:

  1. Get ImageSearch UDF and DLL
  2. Make a picture of the button
  3. Search and click it

NOTE: Sometimes you need to give your script Admin rights in order to automate certain windows.

Upvotes: 1

Related Questions