【问题标题】:GUI automation using pywinauto python. Attribute error , menu_select() missing error in uaicontrols.py使用 pywinauto python 的 GUI 自动化。 uaicontrols.py 中的属性错误,menu_select() 缺失错误
【发布时间】:2019-03-04 09:11:56
【问题描述】:

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

我通过启动打印管理 mmc 来解决此问题,从左窗格中的“打印服务器”下拉菜单中右键单击“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()

如何解决问题?

【问题讨论】:

  • @Vasily Ryabov 从上周开始,我一直在尝试解决这个问题。

标签: python pywinauto


【解决方案1】:

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 版的记录器功能。所以不用过多考虑层次结构,生成脚本会容易得多。

【讨论】:

  • 文件 "step32.py",第 11 行,在 print_servers.child_window(title="G23XNQ2E(local)", control_type="TreeItem").right_click_input() 文件 "C:\ Python37\lib\site-packages\pywinauto\application.py",第 352 行,在 getattribute ctrls = self.__resolve_control(self.criteria)
  • 文件“C:\Python37\lib\site-packages\pywinauto\application.py”,第 249 行,在 __resolve_control 中引发 e.original_exception 文件“C:\Python37\lib\site-packages\ pywinauto\timings.py",第 431 行,在 wait_until_passes 中 func_val = func(*args, **kwargs)
  • 文件“C:\Python37\lib\site-packages\pywinauto\application.py”,第 210 行,在 __get_ctrl ctrl = self.backend.generic_wrapper_class(findwindows.find_element(**ctrl_criteria))文件“C:\Python37\lib\site-packages\pywinauto\findwindows.py”,第 87 行,在 find_element 中引发 ElementNotFoundError(kwargs) pywinauto.findwindows.ElementNotFoundError: {'title': 'G23XNQ2E(local)', 'control_type ': 'TreeItem', 'top_level_only': False, 'parent': , 'backend': 'uia'}
  • 我系统中的任何错误信息。它依赖于系统吗?
  • 代码打开第一个Dialog并等待一段时间给出上述错误。
猜你喜欢
  • 2015-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-20
  • 2017-04-24
  • 2021-04-05
  • 2020-06-30
相关资源
最近更新 更多