python⾃动化⼯具之pywinauto实例详解本⽂实例为⼤家分享了python⾃动化⼯具pywinauto,供⼤家参考,具体内容如下
⼀、win环境应⽤⾃动化
1.浏览器中
2.在cmd下启动:python get-pip.py
3.在cmd中输⼊python -m pip --version查看安装pip的版本。
4.模块安装:pip3 install pywinauto
5.程序中加载模块:
import time
from pywinautoimport application
⼆、实例
#encoding=utf-8
#author: walker
#date: 2018-04-26
#summary: 以 pywinauto 调⽤ ABBYY FineReader 12 Professional 将 pdf 另存为 txt
#sys.version:'3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)]'
import os, sys, time, shutil, ctypes
from pywinauto.application import Application
# 转换单个 pdf 为 txt
# 需要保证输出 txt ⽂件所在⽬录是存在的,txt ⽂件不存在
# 外层许捕获异常
def Pdf2Txt(pdfFile, txtFile):
print('Enter Pdf2Txt ...')
FineReaderPath = r'F:\software\ABBYY FineReader '
UsualTimeout = 30
cmd = r'"%s" "%s"' % (FineReaderPath, pdfFile)
print('cmd: %s' % cmd)
app = Application(backend="win32").start(cmd)
mainWindow = app.window(class_name=r'FineReader12MainWindowClass')
mainWindow.wait("ready", timeout=UsualTimeout)
python安装教程非常详细statButton = mainWindow.child_window(process=app.process, class_name='Button', title_re=r'\d+ OF \d+ PAGES RECOGNIZED') statButton.wait("exists visible", timeout=UsualTimeout)
statButton.wait_not("visible", timeout=RecognizeTimeout) # 具体转换可能要很久
mainWindow.dump_tree(filename='')
mainWindow.ToolbarSave.wait('enabled', timeout=RecognizeTimeout).click() # 点击保存按钮
saveDlg = app.window(class_name=r'#32770', title=r'Save document as')
saveDlg.wait("exists visible", timeout=UsualTimeout)
saveDlg.dump_tree(filename='')
saveDlg.DUIViewWndClassName.DirectUIHWND.ComboBox2.select('Text (*.txt)') # 设置保存格式
saveDlg.DUIViewWndClassName.DirectUIHWND.FloatNotifySink.ComboBox.Edit.set_text(txtFile) # 设置保存⽂件名
saveDlg.DUIViewWndClassName.DirectUIHWND.CheckBox.UncheckByClick() # 取消复选框的选中状态(保存后打开)
# pe_keys(r'%S') # 保存为 txt(Alt + S)
saveDlg.child_window(title="保存(&S)", class_name="Button").wait('ready', timeout=RecognizeTimeout).click() # 点击保存按钮
print('保存(&S) Button clicked!')
saveDlg.wait_not("exists", timeout=UsualTimeout)
cnt = 0
for _ in range(0, 100):
time.sleep(0.1)
cnt += 1
if ists(txtFile):
break
app.kill()
saveDlg.wait_not("exists", timeout=UsualTimeout)
mainWindow.wait_not("exists", timeout=20)
print('not exists mainWindow!')
print('current time:%f (%s)' % (time.time(), time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()))) return True
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论