I have an issue with pywinauto, using the print_control_identifiers() function. I want to view the tree of elements in the current window, I get the following error:
Traceback (most recent call last):
File "C:\formation_uploading__tranco\app\tranco.py", line 170, in run_process
self.process()
File "C:\formation_uploading__tranco\app\tranco.py", line 73, in process
window.print_control_identifiers()
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\application.py", line 624, in print_control_identifiers
ctrl_names = findbestmatch.get_control_names(ctrl, all_ctrls, txt_ctrls)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\findbestmatch.py", line 320, in get_control_names
non_text_names = get_non_text_control_name(control, allcontrols, textcontrols)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\findbestmatch.py", line 219, in get_non_text_control_name
ctrl_r = ctrl.rectangle()
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\base_wrapper.py", line 367, in rectangle
return self.element_info.rectangle
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\uia_element_info.py", line 326, in rectangle
bound_rect = self._element.CurrentBoundingRectangle
_ctypes.COMError: (-2147220991, 'An event was unable to invoke any of the subscribers', (None, None, None, 0, None))
Process finished with exit code 0
My code is:
app = Application(backend="uia").connect(title_re="1С:Предприятие - АТК:Управление грузоперевозками")
window = app.window(title_re="1С:Предприятие - АТК:Управление грузоперевозками")
window.set_focus()
button_5 = window.child_window(title="Разобрать", control_type="Button")
button_5.click_input()
button_6 = window.child_window(title="Перечни", control_type="TabItem")
button_6.click_input()
window.print_control_identifiers()
button_5 and button_6 executed correctly
If I add depth in print_control_identifiers(depth=3), I get the following traceback:
Traceback (most recent call last):
File "C:\formation_uploading__tranco\app\tranco.py", line 170, in run_process
self.process()
File "C:\formation_uploading__tranco\app\tranco.py", line 73, in process
window.print_control_identifiers(depth=3)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\application.py", line 616, in print_control_identifiers
all_ctrls = [this_ctrl, ] + this_ctrl.descendants()
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\base_wrapper.py", line 493, in descendants
return [self.backend.generic_wrapper_class(element_info) for element_info in desc_elements]
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\base_wrapper.py", line 493, in <listcomp>
return [self.backend.generic_wrapper_class(element_info) for element_info in desc_elements]
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\controls\uia_controls.py", line 1102, in __init__
if not self.children() and self.element_info.handle is not None:
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\base_wrapper.py", line 471, in children
return [self.backend.generic_wrapper_class(element_info) for element_info in child_elements]
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\base_wrapper.py", line 471, in <listcomp>
return [self.backend.generic_wrapper_class(element_info) for element_info in child_elements]
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\controls\uiawrapper.py", line 186, in __new__
return super(UIAWrapper, cls)._create_wrapper(cls, element_info, UIAWrapper)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\base_wrapper.py", line 126, in _create_wrapper
new_class = cls_spec.find_wrapper(element_info)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\controls\uiawrapper.py", line 160, in find_wrapper
wrapper_match = UiaMeta.control_type_to_cls[element.control_type]
KeyError: None
Process finished with exit code 0
I also added window.set_focus(), some sleeps for 2-30 seconds, added a window = app.window(title_re="") many times, still got nothing. window.wait('ready', timeout=10) as well. Created a new application after executing these buttons, tried to call the tree already in it, still same errors.
Any ideas how to investigate/what can be done to debug it further?
Which version of pywinauto is installed in your environment?
The last sources on the Github repo have a try-except block for KeyError
around the line 160 in the uiawrapper.py
file, which is mentioned in your traceback.
You can try to install the newest pywinauto from Github directly
pip install git+https://github.com/pywinauto/pywinauto
in case you use the pip package manager.