Jump to content

How to control a button that Unable to focus.


davidsuger
 Share

Recommended Posts

Hi,

I try to create a unattended install script for CPU-Z ftp://ftp.cpuid.com/cpu-z/cpu-z_1.67-setup-en.exe

But AutoIt unable to focus on the button when ControlClick ( "Setup - CPUID CPU-Z", "", "TNewButton2" ), I tied Send("!n") also didn't work.

info.jpg

I get "Unable to focus on button" from below scripts.

; Get window handle
$hUpgradeWin = WinGetHandle ( "[CLASS:TWizardForm; TITLE:Setup - CPUID CPU-Z]" )
If Not IsHWnd ( $hUpgradeWin ) Then
 $bContinue = False
 MsgBox ( 1,1,"Unable to get window Handle")
Else
 $bContinue = True
EndIf
; Activate window handle
If $bContinue Then
 If Not IsHWnd ( WinActivate ( $hUpgradeWin ) ) Then
  $bContinue = False
  MsgBox ( 1,1, "Unable to activate window")
 EndIf
EndIf
; Get control handle
If $bContinue Then
 $hUpdateBtn = ControlGetHandle ( $hUpgradeWin, "", "[CLASS:TNewButton; TEXT:Cancel]" )
 If Not IsHWnd ( $hUpdateBtn ) Then
  $bContinue = False
  MsgBox ( 1,1,"Unable to get button Handle")
 EndIf
EndIf
; Focus on button ( I notice sometimes the click fails when skipping this step )
If $bContinue Then
 If Not ControlFocus ( $hUpgradeWin, "", $hUpdateBtn ) Then
  $bContinue = False
  MsgBox ( 1,1,"Unable to focus on button")
 EndIf
EndIf
; click button
If $bContinue Then
 If Not ControlClick ( $hUpgradeWin, "", $hUpdateBtn ) Then
  $bContinue = False
  MsgBox ( 1,1,"Unable to click button")
 EndIf
EndIf

I want to control this button, so any help would be greatly appreciated.

Link to comment
Share on other sites

Looks like CPU-Z supports a silent installation. So no need to click buttons etc.

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

AutoIt can interact with (most) controls. But we recommend to use a silent install if available.

To get the ControlID use the Windows Info Tool that comes with AutoIt and then pass the ID to the ControlClick function.

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

try this
$hUpdateBtn = ControlGetHandle ( $hUpgradeWin, "", "[CLASS:TNewButton; TEXT:&Cancel]") ;It will click on Cancel.
                          ;or this
$hUpdateBtn = ControlGetHandle ( $hUpgradeWin, "", "[CLASS:TNewButton; ID:?]"); Enter your button id number in the place of "?" question mark.
                                ;instead of
$hUpdateBtn = ControlGetHandle ( $hUpgradeWin, "", "[CLASS:TNewButton; TEXT:Cancel]")

Tell me please.  what happened?

Edited by adnanbaloch

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

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