我是pywinauto的新手,我正在尝试自动化驱动程序测试,并且我尝试连接运行设备管理器窗口,但无法获得任何信息
我使用的是pywinauto:0.6.8
版本和python:3.7.4
app = Application(backend='uia').connect(title='Device Manager')
app.print_control_identifiers()
任何关于如何访问设备管理器和安装/卸载设备驱动程序的示例代码。
感谢您的宝贵时间。
发布于 2020-04-19 14:39:47
有些时刻很复杂,所以我准备了带有注释的代码。
from pywinauto import Application, Desktop
Application().start(r'mmc devmgmt.msc') # mmc.exe spawns a child process
app = Application(backend="uia").connect(path='mmc.exe') # connect to a child one
main = app.window(title='Device Manager')
#main.dump_tree()
# expand group of devices
usb_bus = main.child_window(title="Universal Serial Bus controllers", control_type="TreeItem")
usb_bus.expand()
#usb_bus.dump_tree()
# call context menu for the second USB Root Hub (found_index=1)
second_usb_root_hub = usb_bus.child_window(title="USB Root Hub", control_type="TreeItem", found_index=1)
second_usb_root_hub.click_input(button='right')
# Root of the Context menu is in the system process, so use global Desktop object.
#print(Desktop(backend="uia").windows()) # all top level windows in the system
context_menu = Desktop(backend="uia").window(title='Context')
#context_menu.dump_tree()
# Child menu items are in the mmc.exe but it doesn't matter if we have root menu object.
context_menu.child_window(title="Properties", control_type="MenuItem").invoke()
中间步骤的.dump_tree()
输出提供了关于子元素的最有用的信息。所有child_window()
规范都是从.dump_tree()
输出中复制的。
元素的进程ID可以在Inspect.exe
中查看(可以在Windows SDK中找到):
https://stackoverflow.com/questions/59710431
复制相似问题