您的位置:首页 > 编程语言 > Python开发

python 自动化之pywinauto 安装

2016-12-10 22:38 489 查看
http://blog.sina.com.cn/s/blog_812973c30101snoj.html

官网文档

http://pywinauto.googlecode.com/hg/pywinauto/docs/index.html


安装依赖包

Download pywinauto from https://sourceforge.net/project/showfiles.php?group_id=157379

Unzip the pywinauto zip file to a folder.

Run cd到 pywinauto-0.4.2 目录下,执行 python.exe setup.py install

Install the following Python packages

Optional PIL http://www.pythonware.com/products/pil/index.htm

Optional elementtree http://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 installctypes http://starship.python.net/crew/theller/ctypes/(download
from http://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()

转自http://www.51testing.com/html/85/132585-852513.html

官网上的都是在英文环境下做的测试。在中文环境下 需要在代码前面加 #coding=gb2312 以下是完整官网类似代码

#coding=gb2312

from pywinauto import application

app = application.Application()

app.start_('notepad')

 

app.Notepad.MenuSelect('帮助->关于记事本'.decode('gb2312'))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: