Sign in to follow this  
Followers 0
davidsuger

How to control a button that Unable to focus.

5 posts in this topic

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.

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Water, thanks for you reply.

I am learning how to create install script.

So AutoIt cannot interact with control like this? How to judge which control can interact or not?

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0