pythonwindowspywinauto

error: COMError: (-2147220992, None, (None, None, None, 0, None))


I'm new to pywinauto. I'm trying to work with a Chinese software using the code below:

from pywinauto.application import Application
app = Application(backend="uia").start("../../../../../software/Barometer/GT5101.exe")

dlg_spec = app.window(title=u"气压计")
actionable_dlg = dlg_spec.wait('visible')

dlg_spec['Button6'].click()

and I got the error

--------------------------------------------------------------------------- COMError                                  Traceback (most recent call
last) Cell In[2], line 8
      5 dlg_spec = app.window(title=u"气压计")
      6 actionable_dlg = dlg_spec.wait('visible')
----> 8 dlg_spec['Button6'].click()

File
~\anaconda3\Lib\site-packages\pywinauto\controls\uia_controls.py:121,
in ButtonWrapper.click(self)
    119 """Click the Button control by using Invoke or Select patterns"""
    120 try:
--> 121     self.invoke()
    122 except NoPatternInterfaceError:
    123     self.select()

File
~\anaconda3\Lib\site-packages\pywinauto\controls\uiawrapper.py:513, in
UIAWrapper.invoke(self)
    510 name = self.element_info.name
    511 control_type = self.element_info.control_type
--> 513 self.iface_invoke.Invoke()
    515 if name and control_type:
    516     self.actions.log("Invoked " + control_type.lower() + ' "' + name + '"')

COMError: (-2147220992, None, (None, None, None, 0, None))

Any idea what's happening?

PS: if you want to reproduce the error, here is the software https://drive.google.com/file/d/1xH6ahh87GmR9utxffz40wPkqwKrX-TKZ/view?usp=sharing

With the code above, I expect the software starting data collection, but got the error.


Solution

  • Use .click_input(). Because .click() is an alias of .invoke() which is not always guaranteed to work, because the app should have proper handler for it.

    Method .click_input() should work in any case except locked desktop or minimized Remote Desktop window. Because .click_input() and .type_keys() generate just pure mouse and keyboard events in the system like normal user.