pywinauto: _ctypes.COMError: (-2147467259, 'Unspecified error', (None, None, None, 0, None) )

Hi,

Is some situations i get this COMError. Any ideas?

Code i’m running

import pywinauto

def click_button(button):
    app = pywinauto.Application(backend='uia')
    appconnect = app.connect(path='software.exe')
    window = appconnect.window()
    window.set_focus()
    button = window.child_window(auto_id=button)
    wrapper = button.wrapper_object()
    wrapper.click_input()

click_button('ButtonName')

Error message:

Traceback (most recent call last):
  File "click_button.py", line 14, in <module>
    click_button('ButtonName')
  File "click_button.py", line 10, in click_button
    wrapper = button.wrapper_object()
  File "build\bdist.win-amd64\egg\pywinauto\application.py", line 249, in wrappe
r_object
  File "build\bdist.win-amd64\egg\pywinauto\application.py", line 239, in __reso
lve_control
  File "build\bdist.win-amd64\egg\pywinauto\timings.py", line 402, in wait_until
_passes
  File "build\bdist.win-amd64\egg\pywinauto\application.py", line 202, in __get_
ctrl
  File "build\bdist.win-amd64\egg\pywinauto\findwindows.py", line 84, in find_el
ement
  File "build\bdist.win-amd64\egg\pywinauto\findwindows.py", line 208, in find_e
lements
  File "build\bdist.win-amd64\egg\pywinauto\uia_element_info.py", line 270, in d
escendants
  File "build\bdist.win-amd64\egg\pywinauto\uia_element_info.py", line 249, in _
get_elements
_ctypes.COMError: (-2147467259, 'Unspecified error', (None, None, None, 0, None)
)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 4
  • Comments: 23 (11 by maintainers)

Most upvoted comments

I also encounter this issue when selecting a listview item:

Traceback (most recent call last):
  File "mycode.py", line 227, in define_tool
    dlg_license.ListBox.AllRoundRuntime.select()
  File "C:\Python27\lib\site-packages\pywinauto\controls\uiawrapper.py", line 511, in select self.iface_selection_item.Select()
COMError: (-2147467259, 'Unspecified error', (None, None, None, 0, None))

Yes. Issue is still present with 0.6.3

ptrs_array = self._element.FindAll(tree_scope, cond)

COMError: (-2147467259, ‘Unspecified error’, (None, None, None, 0, None))

The issue is specifically observed for ‘UIA’ backend and when we try to access the elements from new thread.

Operating System - Windows7x86 and 64 bit. Same issue is not seen in Windows8.1 and Windows 10 RS1 and RS2

For me this is 100% reproducible: File ".\pywinauto\uia_element_info.py", line 63, in __init__ self._element = IUIA().iuia.ElementFromHandle(handle_or_elem) _ctypes.COMError: (-2147467259, 'Unspecified error', (None, None, None, 0, None)

This happens always when I call UIAElementInfo(handle) with the handle being the handle from the Word 2010 Save-close dialog on Windows 7 (the dialog that pops up if you want to close Word with unsaved changes). The machine does not need to be locked for this to happen. On Windows 10 the same code works fine.

I’m using a custom function that just executes the function x times and if it still doesn’t work throws an exception. This seems to solve the issue for now, I’ll have to monitor and see if it happens again. FYI the error only occurred when the machine on which the automation ran was locked.

Having the same issue on the windows 10 pywinauto == 0.6.3

app.top_window().print_control_identifiers() - which prints first component and then crash, but if I put the same fragment in try except block, then second call do the job without errors

failure = True
while failure
    try:
        app.top_window().print_control_identifiers()
        failure = False
    except:
        print("-----FAILURE-----")
        failure = True