首页 > 解决方案 > 如何在pywinauto中连接到control.exe的子窗口

问题描述

我可以通过下面的代码打开控制面板,也可以获取所有控制面板项的 dump_tree。我的意图是在一次控制面板下面。当我尝试单击网络和共享中心时出现以下错误。有人可以帮忙吗

我的意图: - 在网络和共享中心的左侧面板中,打开更改高级共享设置 - 在网络发现下,单击“关闭网络发现”选项。-单击“保存更改”-转到工具->文件夹选项->查看。-勾选‘隐藏受保护的操作系统文件 -关闭保存

我的代码:

Application().start(r'control.exe', wait_for_idle=False)
app = Application(backend="uia").connect(title="All Control Panel Items", timeout=10)
main_window = app.window(title="All Control Panel Items")
#main_window.dump_tree()
Network=main_window.child_window(title="Network and Sharing Center", control_type="Hyperlink").select()
Network.select() # it expands the subtree

获取错误:

Traceback (most recent call last):
  File "C:\Users\sandy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pywinauto\uia_defines.py", line 234, in get_elem_interface
    iface = cur_ptrn.QueryInterface(cls_name)
  File "C:\Users\sandy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\comtypes\__init__.py", line 1158, in QueryInterface
    self.__com_QueryInterface(byref(iid), byref(p))
ValueError: NULL COM pointer access

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\sandy\AppData\Local\Programs\Python\Python36-32\My_Test\Step_46.py", line 16, in <module>
    step_34()
  File "C:\Users\sandy\AppData\Local\Programs\Python\Python36-32\My_Test\Step_46.py", line 11, in step_34
    Network=main_window.child_window(title="Network and Sharing Center", control_type="Hyperlink").select()
  File "C:\Users\sandy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pywinauto\controls\uiawrapper.py", line 605, in select
    self.iface_selection_item.Select()
  File "C:\Users\sandy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pywinauto\controls\uiawrapper.py", line 132, in __get__
    value = self.fget(obj)
  File "C:\Users\sandy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pywinauto\controls\uiawrapper.py", line 224, in iface_selection_item
    return uia_defs.get_elem_interface(elem, "SelectionItem")
  File "C:\Users\sandy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pywinauto\uia_defines.py", line 236, in get_elem_interface
    raise NoPatternInterfaceError()
pywinauto.uia_defines.NoPatternInterfaceError

标签: pywinauto

解决方案


NoPatternInterfaceError表示此操作未在应用端实现。SelectionItem 模式通常可用于 ListItem 或 TreeItem 元素。

对于超链接的使用方法.invoke()


推荐阅读