Open file from windows file dialog with python automatically(使用python自动从windows文件对话框打开文件)
问题描述
我进行自动化测试并获得一个文件对话框.我想用 python 或 selenium 从 windows 打开文件对话框中选择一个文件.
注意:该对话框由其他程序提供.我不想用 Tkinter 创建它.
窗口看起来像:
.
如何做到这一点?
考虑使用
代码示例,在记事本中打开文件.请注意,语法取决于区域设置(它使用 GUI 程序中可见的窗口标题/控件标签):
来自 pywinauto 导入应用程序app = application.Application().start_('notepad.exe')app.Notepad.MenuSelect('文件->打开')# app.[窗口标题].[控件名称]...app.Open.Edit.SetText('filename.txt')app.Open.Open.Click()
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.
NOTE: The dialog is given by an other program. I don't want to create it with Tkinter.
The Window looks like:
.
How to do this?
Consider using the pywinauto package. It has a very natural syntax to automate any GUI programs.
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文件对话框打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用python自动从windows文件对话框打开文件


基础教程推荐
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 筛选NumPy数组 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01