w.top_level_parent() raises an exception when w is a "list item" of the Windows start menu
See original GitHub issueExpected Behavior
w.top_level_parent() should not raise a exception when w is a “list item” of the Windows start menu (Like “Google Chrome” or “Notepad++”)
Maybe the exception is raised because “semantic zoom” is not a control type known by Pywinauto? See the screenshot of inspect.exe in this link
Actual Behavior
Traceback (most recent call last):
  File "C:\Users\d_pra\PycharmProjects\pywinauto_recorder\pywinauto_recorder\recorder.py", line 270, in get_wrapper_path
    wrapper_top_level_parent = wrapper.top_level_parent()
  File "D:\Python\lib\site-packages\pywinauto\base_wrapper.py", line 439, in top_level_parent
    return self.parent().top_level_parent()
  File "D:\Python\lib\site-packages\pywinauto\base_wrapper.py", line 439, in top_level_parent
    return self.parent().top_level_parent()
  File "D:\Python\lib\site-packages\pywinauto\base_wrapper.py", line 433, in top_level_parent
    parent = self.parent()
  File "D:\Python\lib\site-packages\pywinauto\base_wrapper.py", line 409, in parent
    return self.backend.generic_wrapper_class(parent_elem)
  File "D:\Python\lib\site-packages\pywinauto\controls\uiawrapper.py", line 186, in __new__
    return super(UIAWrapper, cls)._create_wrapper(cls, element_info, UIAWrapper)
  File "D:\Python\lib\site-packages\pywinauto\base_wrapper.py", line 126, in _create_wrapper
    new_class = cls_spec.find_wrapper(element_info)
  File "D:\Python\lib\site-packages\pywinauto\controls\uiawrapper.py", line 159, in find_wrapper
    if element.control_type in UiaMeta.control_type_to_cls:
  File "D:\Python\lib\site-packages\pywinauto\uia_element_info.py", line 250, in control_type
    return self._get_control_type()
  File "D:\Python\lib\site-packages\pywinauto\uia_element_info.py", line 112, in _get_current_control_type
    return IUIA().known_control_type_ids[self._element.CurrentControlType]
KeyError: 50039
Steps to Reproduce the Problem
In the following code, top_level_parent() raises an exception if the mouse cursor is over a “list item” of the Windows start menu (Like “Google Chrome” or “Notepad++”)
Short Example of Code to Demonstrate the Problem
x, y = win32api.GetCursorPos()
element_from_point = pywinauto.uia_defines.IUIA().iuia.ElementFromPoint(tagPOINT(x, y))
element_info = pywinauto.uia_element_info.UIAElementInfo(element_from_point)
wrapper = pywinauto.controls.uiawrapper.UIAWrapper(element_info)
wrapper_top_level_parent = wrapper.top_level_parent()
Specifications
- Pywinauto version: 0.6.8
 - Python version and bitness: 2.7 64bit
 - Platform and OS: win 10
 
Issue Analytics
- State:
 - Created 3 years ago
 - Comments:12 (12 by maintainers)
 
Top Results From Across the Web
Under which conditions does the Windows 10 start menu use ...
Under which conditions does the Windows 10 start menu use low level files and folders? In contrast to former versions of Windows, the...
Read more >How to get top_level_parent() of an element in the Windows ...
The exception was raised because "semantic zoom" was not a control type known by my typelib wrapper ... Supported starting with Windows 8.1....
Read more >1. Getting Started, Desktop, & Start Menu - Windows 7 - O'Reilly
Getting Started, Desktop, & Start Menu Microsoft wants to make one thing perfectly clear: ... It comes with no email program, no photo...
Read more >Customize the Start Menu in Windows 10 and Windows 11
Right-click a shortcut. You can manage the apps right from the app list in the Start menu. Right-click on an app to view...
Read more >Start menu - Wikipedia
The Start menu is a graphical user interface element used in Microsoft Windows since Windows 95 and in other operating systems.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@airelil, I deleted Lib\site-packages\comtypes\gen and regenerated it running python -m “pywinauto” and now I have SemanticZoom and AppBar in self._control_types!
Maybe when I first started Pywinauto in this env , it was on Windows 7, it generated Lib\site-packages\comtypes\gen without SemanticZoom and AppBar.
Thank you very much for your help!
@beuaaa , you can try to re-generate the COM interfaces in comtypes package. Typically, it means locating your Python comtypes installation and deleting the contents of
genfolder. Since I work with conda environments I have several installations of comtypes and Python. For example, the comtypes for Python 3.7 environment on my machine is located under:C:\Users\XXXX\Miniconda3\envs\py37\Lib\site-packages\comtypes\genOnce the content of this folder is deleted, runningpython -m "pywinauto"would be enough to re-generate the files. You can also explore the files (but don’t change!) The SemantiZoom definitions can be found in _944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0.py That’s the list of files on my machine: