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

2024-06-16 10:23:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试自动化windows gui鼠标点击打印机属性中的复选框。 I get to this by starting print management mmc right clicking on "G23XnQ2E (local)" from "Print Servers" drop down in the left pane and selecting properties, switching to "security tab" and i finally want to select the checkbox against manage printer option "

通过启动打印管理mmc,右键单击左窗格中的“打印服务器”下拉列表中的“G23XnQ2E(本地)”,然后选择“属性”,切换到“安全选项卡”,最后我想选中“管理打印机”选项的复选框。如果我已经从打印机服务器中选择了“G23XnQ2E(local)”,也可以通过直接单击“操作”菜单并选择“属性”来实现。在

我已经尝试了所有可能的方法,但最终总是会出现许多错误,比如“raise AttributeError”、“menu\u 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()

如何解决这个问题?在


Tags: app属性application打印机actionselect复选框dialog
1条回答
网友
1楼 · 发布于 2024-06-16 10:23:21

menu_select适用于主菜单,如“文件->打开”。它不适用于弹出菜单/上下文菜单。这是我在我的电脑上工作的代码(打印服务器的名称已更改为您的名称):

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()输出复制。有些窗口是主窗口的子窗口,但上下文菜单是顶级窗口。这不是一个记录在案的经验,但我们正在开发一个录音功能,计划今年作为测试版。因此,在不考虑太多层次结构的情况下生成脚本将更加容易。在

相关问题 更多 >