http://blog.sina.com.cn/s/blog_812973c30101snoj.html
官网文档
http://pywinauto.googlecode.com/hg/pywinauto/docs/index.html
安装依赖包
- Download pywinauto fromhttps://sourceforge.net/project/showfiles.php?group_id=157379
- Unzip the pywinauto zip file to a folder.
- Run cd到 pywinauto-0.4.2 目录下,执行python.exesetup.pyinstall
- Install the following Python packages
- OptionalPILhttp://www.pythonware.com/products/pil/index.htm
- Optionalelementtreehttp://effbot.org/downloads/
- Releases prior to 0.3.9 requireSendkeys-http://www.rutherfurd.net/python/sendkeys/index.html
- If you are using Python 2.3 or 2.4 then you will have to installctypeshttp://starship.python.net/crew/theller/ctypes/(download fromhttp://sourceforge.net/project/showfiles.php?group_id=71702)
To check you have it installed correctly Run Python
实现NOTEPAD自动化写及保存
from pywinauto import Application
import time
app = Application.start("notepad")
app.__setattr__("name","notepad")
time.sleep(2)
app.Notepad.edit.TypeKeys('Test ......................')
app.Notepad.edit.TypeKeys('Test ......................')
time.sleep(2)
#中文版本操作
app.Notepad.MenuSelect(u"文件(F)->另存为(A)...")
app.Dialog.edit.TypeKeys(u'TestFile.txt')
time.sleep(2)
#点击保存
app.Dialog.Button1.Click()
time.sleep(2)
#文件存在的话,要覆盖,所以再一次点击是
app.Dialog.Button1.Click()
time.sleep(1)
#退出notepad
app.Notepad.Close()
官网上的都是在英文环境下做的测试。在中文环境下 需要在代码前面加 #coding=gb2312 以下是完整官网类似代码
#coding=gb2312
from pywinauto import application
app = application.Application()
app.start_('notepad')
app.Notepad.MenuSelect('帮助->关于记事本'.decode('gb2312'))