使用 pywinauto python 的 GUI 自动化。属性错误,menu_select() uaicontrols.py 中缺少错误

GUI automation using pywinauto python. Attribute error , menu_select() missing error in uaicontrols.py

我正在尝试自动执行 windows gui 鼠标单击打印机属性中的复选框。

我通过启动打印管理 mmc,右键单击左窗格中 "Print Servers" 下拉列表中的 "G23XnQ2E (local)" 和 selecting 属性,切换到 "security tab" 最后我想 select 复选框管理打印机选项。这也可以通过直接单击操作菜单和 selecting 属性来实现,前提是我已经从打印机服务器 selected "G23XnQ2E (local)"。

我已经尝试了所有可能的方法,但总是会遇到许多错误,例如 "raise AttributeError"、"menu_select"、"select()"、"click()" - "missing".

我的代码就像说:

from pywinauto import Application

Application().start(r'mmc printmanagement.msc') 
app = Application(backend="uia").connect(path='mmc.exe')
app.PrintManagement.dump_tree() 
app.dialog.pane1.pane5.pane6.menu.menu_select("Action -> Properties")
#app.dialog.menu_select("Action -> Properties")
#app.dialog.pane1.pane5.pane6.menu.ActionMentuitem.select()
#app.dialog.pane1.pane5.pane6.menu.ActionMentuitem.click()

如何解决这个问题?

menu_select 适用于像 "File->Open" 这样的主菜单。它不适用于 popup/context 菜单。这是我在 PC 上运行的代码(打印服务器的名称已更改为您的名称):

from pywinauto import Application

Application().start(r'mmc printmanagement.msc') 
app = Application(backend="uia").connect(path='mmc.exe')
#app.PrintManagement.dump_tree()

print_servers = app.PrintManagement.child_window(title="Print Servers", control_type="TreeItem")
print_servers.select() # it expands the subtree

# call popup menu
print_servers.child_window(title="G23XZNQ2E (local)", control_type="TreeItem").right_click_input()

# alternative way to call popup menu
#print_servers.child_window(title_re=".*\(local\)$", control_type="TreeItem").right_click_input()

# select "Properties..." menu item
app.ContextMenu.child_window(title="Properties...", control_type="MenuItem").select()

#app.PrintManagement.Print_Server_Properties.dump_tree()
app.PrintManagement.Print_Server_Properties.TabControl.select('Security')
app.PrintManagement.Print_Server_Properties.child_window(title="Allow Manage Printers", control_type="CheckBox").toggle()

所有 child_window 规范已从 dump_tree() 输出中复制。有些 windows 是主要 window 的子项,但上下文菜单是顶级菜单。这不是记录在案的体验,但我们正在研究今年计划作为 Beta 的记录器功能。所以不用考虑层级结构,生成脚本会容易很多。