Pywinauto使用click()启动按钮控件并自动安装驱动程序时出现意外结果

时间:2018-07-27 02:32:36

标签: python ui-automation pywinauto

最近第一次研究Python和自动化,因此请原谅我的任何无知。

尝试自动安装POS单元的现金抽屉驱动程序。

我已经类似于此问题中提供的答案对代码进行了建模: How to access the control identifiers in pywinauto

代码:

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()

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

我需要启动的控件:

| Button - '&Next >'    (L2170, T734, R2258, B756)
| ['&Next >', '&Next >Button', 'Button', 'Button0', 'Button1']
| child_window(title="&Next >", class_name="Button")

代码和输出:

dlg.Next.Click()
<win32_controls.ButtonWrapper - '&Next >', Button, 3277910>

我发现混乱的是初始化代码时,什么都没发生,

就像我两次输入相同的命令一样:

>>> dlg.Next.Click()
<win32_controls.ButtonWrapper - '&Next >', Button, 6621356>
>>> dlg.Next.Click()
<win32_controls.ButtonWrapper - 'None', Button, 6621356>

它成功单击按钮并将字符串从“&Next>”更改为“ None”,

使用时的结果相同:

>>> dlg.Button.Click()
<win32_controls.ButtonWrapper - '&Next >', Button, 1970898>
>>> dlg.Button.Click()
<win32_controls.ButtonWrapper - 'None', Button, 1970898>

任何指导表示赞赏。

0 个答案:

没有答案