Search code examples
pywinauto

How to connect to child window of control.exe in pywinauto


I am able to open Control panel through below code, able to get dump_tree of All Control Panel Items too. My intension is below once control panel. When I tried to click on Network and sharing Center getting below error. Could anyone help on this

My intension: -In the left panel of Network and sharing Center, open Change Advanced sharing setting -Under network discovery, Click on ‘Turn off network discovery” option. -Click “Save Changes” -Go to Tools->Folder Options->View. -Check 'Hide protected operating system files -Close to save

My code:

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

Error getting:

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

Solution

  • NoPatternInterfaceError means that this action is not implemented on the app side. SelectionItem pattern is usually available for ListItem or TreeItem elements.

    For hyperlink use method .invoke().