我进行自动化测试并获得一个文件对话框.我想用 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文件对话框打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
python:不同包下同名的两个模块和类python: Two modules and classes with the same name under different packages(python:不同包下同名的两个模块和类)
配置 Python 以使用站点包的其他位置Configuring Python to use additional locations for site-packages(配置 Python 以使用站点包的其他位置)
如何在不重复导入顶级名称的情况下构造python包How to structure python packages without repeating top level name for import(如何在不重复导入顶级名称的情况下构造python包)
在 OpenShift 上安装 python 包Install python packages on OpenShift(在 OpenShift 上安装 python 包)
如何刷新 sys.path?How to refresh sys.path?(如何刷新 sys.path?)
分发带有已编译动态共享库的 Python 包Distribute a Python package with a compiled dynamic shared library(分发带有已编译动态共享库的 Python 包)