python自动化安装软件,如何创建Python脚本来自动化软件安装?

I want to automate the software installation process. The scenario is as follows:

Run the installation file. On first screen it has two buttons next, cancel. On click of next it goes to next screen having two buttons, next, cancel and some input data is required. After details are provided, it will show finish or cancel button.

I want to write a Python script that would automate this activity. It should identify the button and click it. It should enter the data wherever required and finish the installation. To achieve this functionality:

Python API is required, if any?

Some code samples or link of the tutorials to use the same.

Sample image for reference:

WLyqh.jpg

解决方案

As Rawing mentioned, pywinauto is good choice for Windows installer. Here is nice sample video: http://pywinauto.github.io/

For waiting next page use something like that: app.WizardPageTitle.wait('ready')

When installer finished: app.FinishPage.wait_not('visible')

For edit box input: app.WizardPage.Edit.type_keys('some input path', with_spaces=True)

For button clicks I'd recommend click_input() as more reliable method.

If you want to install the app on many machines automatically, you can create Remote Desktop or VNC session and run local copy of the Python script inside that session. Just do not minimize RDP or VNC window to prevent GUI context loss. Losing focus is safe and you can continue your work on master machine in another window without affecting remote installation.

Example of easy install script for FastStone Image Viewer 4.6:

import os

from pywinauto.application import Application

fsv = Application(backend="win32").start("FSViewerSetup46.exe")

fsv.InstallDialog.NextButton.wait('ready', timeout=30).click_input()

fsv.InstallDialog.IAgreeRadioButton.wait('ready', timeout=30).click_input()

fsv.InstallDialog.Edit.Wait('ready', timeout=30).type_keys(os.getcwd() + "\FastStone Image Viewer", with_spaces=True)

fsv.InstallDialog.InstallButton.wait('ready', timeout=30).click_input()

fsv.InstallDialog.FinishButton.wait('ready', timeout=30).click_input()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值