使用python自动从windows文件对话框打开文件

Open file from windows file dialog with python automatically(使用python自动从windows文件对话框打开文件)
本文介绍了使用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文件对话框打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)