如何对特定文件执行上下文菜单操作?
我设法打开资源管理器,使用pywinauto通过python获取文件列表。
在这个文件上,我需要执行上下文菜单操作,是否可以通过pywinauto执行?
import pywinauto
path = "C:\\Users\\Vishnu\\Desktop\\DM-test\\"
pywinauto.Application().Start(r'explorer.exe')
explorer = pywinauto.Application().Connect(path='explorer.exe')
NewWindow = explorer.Window_(top_level_only=True, active_only=True, class_name='CabinetWClass')
NewWindow.AddressBandRoot.ClickInput()
NewWindow.TypeKeys(path+'{ENTER}', with_spaces=True, set_foreground=False)
上面的代码将打开资源管理器并导航到目录。这是对该文件所需的上下文菜单操作:
我设法找到了reg值,并更改了代码以将该操作传递给文件,它工作得很完美!
pywinauto.Application().start(r'"C:\Program Files (x86)\Qualcomm\QCAT 6.x\Bin\QCAT.exe" -txt "{}"'.format(fileName))
发布于 2018-06-03 04:31:48
啊!没人看文档..。示例位于主自述文件:MS UI Automation Example中。对于您的情况,它应该是这样的:
# no need to type the path, explorer.exe has a cmd param for that
pywinauto.Application().start(r'explorer.exe "{}"'.format(path))
# backend is important!!!
app = Application(backend="uia").connect(path="explorer.exe")
NewWindow = explorer.Window_(top_level_only=True, active_only=True, class_name='CabinetWClass')
file_item = NewWindow.ItemsView.get_item('dmlog20180517-121505slot0.dlf')
file_item.right_click_input()
app.ContextMenu["Convert to QCAT Text"].invoke()
# further actions depend on a process / dialog started...
更多关于后端的详细信息:Getting Started Guide。
https://stackoverflow.com/questions/50655635
复制相似问题