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

标签 python pywinauto

我正在尝试自动执行 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 来实现这一点,右键单击左 Pane 中“打印服务器”下拉菜单中的“G23XnQ2E(本地)”并选择属性,切换到“安全选项卡”,最后我想选择针对管理打印机选项的复选框。这也可以通过直接单击操作菜单并选择属性来实现,前提是我从打印机服务器中选择了“G23XnQ2E(本地)”。

我已经尝试了所有可能的方法,但总是会遇到许多错误,例如“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 适用于“文件->打开”等主菜单。它不适用于弹出菜单/上下文菜单。这是我在 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() 输出中复制。有些窗口是主窗口的子窗口,但上下文菜单是顶级窗口。这不是记录在案的体验,但我们正在研究今年计划作为 Beta 的记录器功能。因此,无需过多考虑层次结构,生成脚本会容易得多。

关于python - 使用 pywinauto python 的 GUI 自动化。属性错误,uaicontrols.py 中的 menu_select() 缺失错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54951778/

相关文章:

python - PyWinAuto 仍然有用吗?

python-3.x - 使用 pywinauto 迭代子菜单项

python - 函数调用之外的星号

python - 如何建立三次抛硬币的贝叶斯仿真模型

Python BeautifulSoup - 无法读取网站分页

python - 监视文件夹和打印 - 不使用 "endless"while 循环的替代方法?

python - 无法从 pywinauto 导入 : ImportError: DLL load failed while importing win32ui: A dynamic link library (DLL) initialization routine failed

python - 使用 pywinauto 查找 GUI 元素

python - Keras - 如何使用 2 个独立的全连接层共享 CNN 的卷积部分

python - 导入错误 : DLL load failed with pybind11 and PCL