Reputation: 37
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
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:
Upvotes: 0
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:
WindowActivate
Send
ENTER or SPACEMethod 2 - MouseClick
:
Autoit Window Info
, click on Mouse tab and get the position of the button). That position is usually always the sameWinGetPos
and then add control position you got in step 2. That's your clicking position.Method 3 - PixelSearch
(If the control has unique color):
AutoIt Window Info
(mouse tab)PixelSearch
Method 4 - ImageSearch:
ImageSearch
UDF and DLLNOTE: Sometimes you need to give your script Admin rights in order to automate certain windows.
Upvotes: 1