I wrote a program to automate the test of an app i did not create using pywinauto, but i got this error : pywinauto.uia_defines.NoPatternInterfaceError. It came when i tried this :
app.connect(path=exe_path)
main_dlg = app.top_window()
main_dlg.wait('visible')
truc = main_dlg.child_window(title="Users", control_type="Button")
truc.click() # <- this is where the problem arised
Here is the code (so that you understand the context) :
from pywinauto.application import Application
*
* This is irrevelent
*
try:
print("start")
app = Application(backend="uia").start(exe_path)
app.connect(path=exe_path)
main_dlg = app.top_window()
print("Is there a window : "+ str(main_dlg.exists()))
main_dlg.wait('visible')
# Here we can start to work
# This let us see what the API see in the selected window
main_dlg.print_control_identifiers()
print(str(main_dlg.actions))
truc = main_dlg.child_window(title="Users", control_type="Button")
print(type(truc))
print(str(truc))
truc.print_control_identifiers()
truc.click()
except Exception as e:
print("PROBLEM")
print("--------------------------------------------------------------")
raise(e)
finally:
print("Finally")
And here is what it print :
C:\Users\vboxuser\Documents\GST_tests\automation.py:3: SyntaxWarning: invalid escape sequence '\P'
exe_path = "xxx"
start
Is there a window : True
Control Identifiers:
Dialog - 'xxx' (L-8, T-8, R1928, B868)
['xxxDialog', 'Dialog', 'xxx']
child_window(title="xxx", control_type="Window")
|
| TitleBar - '' (L16, T-5, R1920, B23)
| ['TitleBar']
| |
| | Menu - 'Système' (L0, T0, R22, B22)
| | ['SystèmeMenu', 'Système', 'Menu', 'Système0', 'Système1']
| | child_window(title="Système", auto_id="MenuBar", control_type="MenuBar")
| | |
| | | MenuItem - 'Système' (L0, T0, R22, B22)
| | | ['Système2', 'MenuItem', 'SystèmeMenuItem']
| | | child_window(title="Système", control_type="MenuItem")
| |
| | Button - 'Réduire' (L1779, T8, R1826, B22)
| | ['Button', 'Réduire', 'RéduireButton', 'Button0', 'Button1']
| | child_window(title="Réduire", control_type="Button")
| |
| | Button - 'Restaurer' (L1826, T8, R1872, B22)
| | ['Button2', 'RestaurerButton', 'Restaurer']
| | child_window(title="Restaurer", control_type="Button")
| |
| | Button - 'Fermer' (L1872, T8, R1928, B22)
| | ['Button3', 'FermerButton', 'Fermer']
| | child_window(title="Fermer", control_type="Button")
|
| Image - '' (L16, T39, R408, B103)
| ['Image']
|
| Button - 'Logon' (L0, T120, R100, B170)
| ['Logon', 'Button4', 'LogonButton', 'Logon0', 'Logon1']
| child_window(title="Logon", control_type="Button")
| |
| | Static - 'Logon' (L33, T137, R67, B152)
| | ['Logon2', 'Static', 'LogonStatic', 'Static0', 'Static1']
| | child_window(title="Logon", control_type="Text")
|
| Button - 'Hardware' (L0, T170, R100, B220)
| ['Hardware', 'Button5', 'HardwareButton', 'Hardware0', 'Hardware1']
| child_window(title="Hardware", control_type="Button")
| |
| | Static - 'Hardware' (L24, T187, R76, B202)
| | ['Hardware2', 'Static2', 'HardwareStatic']
| | child_window(title="Hardware", control_type="Text")
|
| Button - 'SNTP' (L0, T220, R100, B270)
| ['Button6', 'SNTP', 'SNTPButton', 'SNTP0', 'SNTP1']
| child_window(title="SNTP", control_type="Button")
| |
| | Static - 'SNTP' (L36, T237, R64, B252)
| | ['SNTPStatic', 'Static3', 'SNTP2']
| | child_window(title="SNTP", control_type="Text")
|
| Button - 'Network' (L0, T270, R100, B320)
| ['Button7', 'NetworkButton', 'Network', 'Network0', 'Network1']
| child_window(title="Network", control_type="Button")
| |
| | Static - 'Network' (L27, T287, R73, B302)
| | ['Static4', 'NetworkStatic', 'Network2']
| | child_window(title="Network", control_type="Text")
|
| Button - 'Users' (L0, T320, R100, B370)
| ['UsersButton', 'Button8', 'Users', 'Users0', 'Users1']
| child_window(title="Users", control_type="Button")
| *
| *
| *
| * Not useful info that i cut
| *
| *
| *
| Button - 'Firmware' (L0, T570, R100, B620)
| ['Button13', 'Firmware', 'FirmwareButton', 'Firmware0', 'Firmware1']
| child_window(title="Firmware", control_type="Button")
| |
| | Static - 'Firmware' (L26, T587, R74, B602)
| | ['Static10', 'FirmwareStatic', 'Firmware2']
| | child_window(title="Firmware", control_type="Text")
<pywinauto.actionlogger._StandardLogger object at 0x000001C3EC87B290>
<class 'pywinauto.application.WindowSpecification'>
<pywinauto.application.WindowSpecification object at 0x000001C3EDAC3410>
Control Identifiers:
Button - 'Users' (L0, T320, R100, B370)
['UsersButton', 'Button', 'Users', 'Users0', 'Users1']
child_window(title="Users", control_type="Button")
|
| Static - 'Users' (L36, T337, R64, B352)
| ['Static', 'Users2', 'UsersStatic']
| child_window(title="Users", control_type="Text")
PROBLEM
--------------------------------------------------------------
Finally
Traceback (most recent call last):
File "C:\Users\vboxuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pywinauto\uia_defines.py", line 234, in get_elem_interface
iface = cur_ptrn.QueryInterface(cls_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\vboxuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\comtypes\__init__.py", line 828, 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\vboxuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pywinauto\controls\uia_controls.py", line 121, in click
self.invoke()
File "C:\Users\vboxuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pywinauto\controls\uiawrapper.py", line 513, in invoke
self.iface_invoke.Invoke()
^^^^^^^^^^^^^^^^^
File "C:\Users\vboxuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pywinauto\controls\uiawrapper.py", line 132, in __get__
value = self.fget(obj)
^^^^^^^^^^^^^^
File "C:\Users\vboxuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pywinauto\controls\uiawrapper.py", line 231, in iface_invoke
return uia_defs.get_elem_interface(elem, "Invoke")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\vboxuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pywinauto\uia_defines.py", line 236, in get_elem_interface
raise NoPatternInterfaceError()
pywinauto.uia_defines.NoPatternInterfaceError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\vboxuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pywinauto\uia_defines.py", line 234, in get_elem_interface
iface = cur_ptrn.QueryInterface(cls_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\vboxuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\comtypes\__init__.py", line 828, 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\vboxuser\Documents\GST_tests\automation.py", line 31, in <module>
raise(e)
File "C:\Users\vboxuser\Documents\GST_tests\automation.py", line 26, in <module>
truc.click()
File "C:\Users\vboxuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pywinauto\controls\uia_controls.py", line 123, in click
self.select()
File "C:\Users\vboxuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pywinauto\controls\uiawrapper.py", line 605, in select
self.iface_selection_item.Select()
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\vboxuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pywinauto\controls\uiawrapper.py", line 132, in __get__
value = self.fget(obj)
^^^^^^^^^^^^^^
File "C:\Users\vboxuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pywinauto\controls\uiawrapper.py", line 224, in iface_selection_item
return uia_defs.get_elem_interface(elem, "SelectionItem")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\vboxuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pywinauto\uia_defines.py", line 236, in get_elem_interface
raise NoPatternInterfaceError()
pywinauto.uia_defines.NoPatternInterfaceError
From what i understand and what i saw in the documentation and the exemples, Users Button should be a clickable element. Did i do something wrong ?
Also, i found this post : github issue link that seems to have a similar issue. I also tried to use win32 backend instead of uia, but i got the same result as ripdog.
In the end it can be sumurised as : Is it my fault ? Is there an alternative way to click Button elements ?
Unfortunately not every application implements click handlers and other handlers properly on the application side. So it is kind of norm. :( But methods .click_input()
, .type_keys(...)
and similar should always work since they use native mouse and keyboard events. They only need active desktop: it means the PC is not locked or RDP window is not minimized and not disconnected. About RDP you can read Remote Execution Guide for proper settings and other workarounds