Pywinauto unintended result when initiating button control with click(), automating install of driver
Pywinauto unintended result when initiating button control with click(), automating install of driver
Recently delving into Python and automation for the first time so please forgive me for any unintended ignorance.
Trying to automate the installation of a cash drawer driver for POS units.
I have modelled my code similarily to the answer provided in this question:
How to access the control identifiers in pywinauto
The code:
from pywinauto import application, findwindows, handleprops
app = application.Application() # create 'app' instance object
app.start("C:/POS Post install/1_setup.exe") #start installer within
instance
handle_variable = findwindows.find_windows(class_name =
"MsiDialogCloseClass") # variable containing handle of installer
dlg = app.window_(handle = handle_variable[0]) # specify dialogue
dlg.print_control_identifiers()
The output of print_control_identifiers():
Control Identifiers:
MsiDialogCloseClass - 'OPOS CashDrawer Driver - InstallShield Wizard'
(L1861, T384, R2365, B767)
['OPOS CashDrawer Driver - InstallShield Wizard', 'MsiDialogCloseClass',
'OPOS CashDrawer Driver - InstallShield WizardMsiDialogCloseClass']
child_window(title="OPOS CashDrawer Driver - InstallShield Wizard",
class_name="MsiDialogCloseClass")
|
| Button - '&Next >' (L2170, T734, R2258, B756)
| ['&Next >', '&Next >Button', 'Button', 'Button0', 'Button1']
| child_window(title="&Next >", class_name="Button")
|
| Button - 'Cancel' (L2265, T734, R2353, B756)
| ['Cancel', 'CancelButton', 'Button2']
| child_window(title="Cancel", class_name="Button")
|
| Button - '< &Back' (L2082, T734, R2170, B756)
| ['< &BackButton', 'Button3', '< &Back']
| child_window(title="< &Back", class_name="Button")
|
| Static - 'WARNING: This program is protected by copyright law and
international treaties.' (L2044, T602, R2348, B699)
| ['WARNING: This program is protected by copyright law and international
treaties.', 'WARNING: This program is protected by copyright law and
international treaties.Static', 'Static', 'Static0', 'Static1']
| child_window(title="WARNING: This program is protected by copyright law and
international treaties.", class_name="Static")
|
| Static - 'The InstallShield(R) Wizard will install OPOS CashDrawer Driver
on your computer. To continue, click Next.' (L2044, T483, R2348, B543)
| ['The InstallShield(R) Wizard will install OPOS CashDrawer Driver on your
computer. To continue, click Next.Static', 'The InstallShield(R) Wizard will
install OPOS CashDrawer Driver on your computer. To continue, click Next.',
'Static2', 'The InstallShield(R) Wizard will install OPOS CashDrawer Driver
on your computer. To continue, click Next.Static0', 'The InstallShield(R)
Wizard will install OPOS CashDrawer Driver on your computer. To continue,
click Next.Static1']
| child_window(title="The InstallShield(R) Wizard will install OPOS
CashDrawer Driver on your computer. To continue, click Next.",
class_name="Static")
|
| Static - '' (L1864, T722, R2360, B724)
| ['The InstallShield(R) Wizard will install OPOS CashDrawer Driver on your
computer. To continue, click Next.Static2', 'NewBinary5Static', 'Static3',
'NewBinary5Static0', 'NewBinary5Static1']
| child_window(class_name="Static")
|
| Static - 'NewBinary5' (L1864, T410, R2362, B722)
| ['NewBinary5', 'NewBinary5Static2', 'Static4']
| child_window(title="NewBinary5", class_name="Static")
|
| Static - 'Welcome to the InstallShield Wizard for OPOS CashDrawer Driver'
(L2044, T420, R2344, B480)
| ['Welcome to the InstallShield Wizard for OPOS CashDrawer DriverStatic',
'Welcome to the InstallShield Wizard for OPOS CashDrawer Driver', 'Static5']
| child_window(title="Welcome to the InstallShield Wizard for OPOS CashDrawer
Driver", class_name="Static")
The control I need to initiate:
| Button - '&Next >' (L2170, T734, R2258, B756)
| ['&Next >', '&Next >Button', 'Button', 'Button0', 'Button1']
| child_window(title="&Next >", class_name="Button")
code and output:
dlg.Next.Click()
<win32_controls.ButtonWrapper - '&Next >', Button, 3277910>
What I'm finding confusing is when initialising the code, nothing happens,
Where as if I input the same command twice:
>>> dlg.Next.Click()
<win32_controls.ButtonWrapper - '&Next >', Button, 6621356>
>>> dlg.Next.Click()
<win32_controls.ButtonWrapper - 'None', Button, 6621356>
It successfully clicks the button and changes the string from '&Next >' to 'None',
Same result when using:
>>> dlg.Button.Click()
<win32_controls.ButtonWrapper - '&Next >', Button, 1970898>
>>> dlg.Button.Click()
<win32_controls.ButtonWrapper - 'None', Button, 1970898>
Any guidance is appreciated.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.