問題描述
我進行自動化測試并獲得一個文件對話框.我想用 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模板網!