使用python自动从Windows文件对话框中打开文件 [英] Open file from windows file dialog with python automatically

查看:1079
本文介绍了使用python自动从Windows文件对话框中打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行自动化测试并获得文件对话框.我想从Windows使用python或硒的打开文件对话框中选择一个文件.

I do automated testing and get a file dialog. I want to choose a file from the windows open file dialog with python or selenium.

注意:该对话框是由另一个程序给出的.我不想用Tkinter创建它.

NOTE: The dialog is given by an other program. I don't want to create it with Tkinter.

窗口看起来像:

.

该怎么做?

推荐答案

考虑使用 pywinauto 软件包.它具有非常自然的语法,可以自动执行任何GUI程序.

Consider using the pywinauto package. It has a very natural syntax to automate any GUI programs.

代码示例,在记事本中打开文件.请注意,语法是与语言环境相关的(它使用GUI程序中的可见窗口标题/控件标签):

Code example, opening a file in notepad. Note that the syntax is locale dependent (it uses the visible window titles / control labels in your GUI program):

from pywinauto import application
app = application.Application().start_('notepad.exe')
app.Notepad.MenuSelect('File->Open')
# app.[window title].[control name]...
app.Open.Edit.SetText('filename.txt')
app.Open.Open.Click()

这篇关于使用python自动从Windows文件对话框中打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆