how to switch between two application using pywinauto 0.5.4

微笑、不失礼 提交于 2020-01-23 16:11:30

问题


I am trying to automate a task of copying every single line one by one from Notepad and pasting it the application and then clicking at a button and then copying the output to a third notepad file.
I am using pywinauto 0.5.4 of python for this automation and I am not getting any help on how to switch between different application

from pywinauto import application

app = application.Application()
app = application.Application()
app.start("Notepad.exe")
app.start("C:\Program Files (x86)\eSpeak\eSpeakedit.exe")

I am using this code for starting two apps. How to switch between these two application at will?


回答1:


This code should do the trick:

from pywinauto import application

app = application.Application()
app2 = application.Application()
app.start("Notepad.exe")
app2.start(r"C:\Program Files (x86)\eSpeak\eSpeakedit.exe")

# switch to Notepad
app.UntitledNotepad.SetFocus()
# select and copy next line (this is not the only way, just for example)
app.UntitledNotepad.Edit.TypeKeys('{DOWN}{HOME}+{END}^c')

 # switch to your app
app2.SpeakEditWindowTitle.SetFocus()
# paste somewhere


来源:https://stackoverflow.com/questions/40222050/how-to-switch-between-two-application-using-pywinauto-0-5-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!