Correct answer is that you missed top_level_only=False (it's True by default because higher level API calls it at least twice). Then you may have 2 controls matching this criterion (maybe from different applications). find_element is a low level function. I wouldn't recommend its direct usage (the code is too long, there are many pitfalls that were taken into account on a higher level API).

>>> pywinauto.findwindows.find_element(class_name="Button", control_id=2, top_level_only=False)
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "...\pywinauto\findwindows.py", line 98, in find_element
    raise exception
ElementAmbiguousError: There are 2 elements that match the criteria {'class_name': 'Button', 'control_id': 2, 'top_level_only': False}

>>> pywinauto.findwindows.find_element(class_name="Button", title='Cancel', top_level_only=False)
<win32_element_info.HwndElementInfo - 'Cancel', Button, 395554>

Using higher level API (Application object and WindowSpecifications described in the Guide) you shouldn't care about passing process id, backend name and other things to find_element every time.

P.S. In my mind SWAPY could be significantly improved, but it's not maintained last year. I hope to re-write it in the future with smaller code base and MS UI Automation support. But currently fully automatic script generator is a higher priority.


EDIT:

This button w_open['SplitButton6'].draw_outline() could be detected as general HwndWrapper object instead of ButtonWrapper. You can check it using this:

w_open['SplitButton6'].wrapper_object()

And this is what exactly written in the Getting Started Guide (which you said you've read).

Fortunately you can use method .click_input() for any control:

w_open['SplitButton6'].click_input()

I can say more: WindowSpecification does NOT have click method. It's a method of ButtonWrapper which is instantiated dynamically. For example these statements work the same way (but Python can hide .wrapper_object() call):

w_open['SplitButton6'].wrapper_object().click_input()
w_open['SplitButton6'].click_input()

And again this is all described in the Getting Started Guide. Please read the whole guide. You will find many useful high level things. I can advise for some corner cases if something is still not clear.

Answer from Vasily Ryabov on Stack Overflow
🌐
Readthedocs
pywinauto.readthedocs.io › en › latest › code › pywinauto.findwindows.html
pywinauto.findwindows — pywinauto 0.6.8 documentation
exception pywinauto.findwindows.ElementNotFoundError¶ · No element could be found · exception pywinauto.findwindows.WindowAmbiguousError¶ · There was more then one window that matched · exception pywinauto.findwindows.WindowNotFoundError¶ · No window could be found ·
Top answer
1 of 1
4

Correct answer is that you missed top_level_only=False (it's True by default because higher level API calls it at least twice). Then you may have 2 controls matching this criterion (maybe from different applications). find_element is a low level function. I wouldn't recommend its direct usage (the code is too long, there are many pitfalls that were taken into account on a higher level API).

>>> pywinauto.findwindows.find_element(class_name="Button", control_id=2, top_level_only=False)
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "...\pywinauto\findwindows.py", line 98, in find_element
    raise exception
ElementAmbiguousError: There are 2 elements that match the criteria {'class_name': 'Button', 'control_id': 2, 'top_level_only': False}

>>> pywinauto.findwindows.find_element(class_name="Button", title='Cancel', top_level_only=False)
<win32_element_info.HwndElementInfo - 'Cancel', Button, 395554>

Using higher level API (Application object and WindowSpecifications described in the Guide) you shouldn't care about passing process id, backend name and other things to find_element every time.

P.S. In my mind SWAPY could be significantly improved, but it's not maintained last year. I hope to re-write it in the future with smaller code base and MS UI Automation support. But currently fully automatic script generator is a higher priority.


EDIT:

This button w_open['SplitButton6'].draw_outline() could be detected as general HwndWrapper object instead of ButtonWrapper. You can check it using this:

w_open['SplitButton6'].wrapper_object()

And this is what exactly written in the Getting Started Guide (which you said you've read).

Fortunately you can use method .click_input() for any control:

w_open['SplitButton6'].click_input()

I can say more: WindowSpecification does NOT have click method. It's a method of ButtonWrapper which is instantiated dynamically. For example these statements work the same way (but Python can hide .wrapper_object() call):

w_open['SplitButton6'].wrapper_object().click_input()
w_open['SplitButton6'].click_input()

And again this is all described in the Getting Started Guide. Please read the whole guide. You will find many useful high level things. I can advise for some corner cases if something is still not clear.

🌐
Stack Overflow
stackoverflow.com › questions › 76834270 › pywinauto-findwindows-elementnotfounderror
python - pywinauto.findwindows.ElementNotFoundError - Stack Overflow
Traceback (most recent call last): ...^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Python311\Lib\site-packages\pywinauto\findwindows.py", line 87, in find_element raise ElementNotFoundError(kwargs) pywinauto.findwindows.ElementNotFoundError: {'title': 'test123', 'control_type': ...
🌐
Readthedocs
pywinauto.readthedocs.io › en › uia › code › pywinauto.findwindows.html
pywinauto.findwindows — pywinauto 0.6.0.rc1 documentation
exception pywinauto.findwindows.ElementNotFoundError¶ · No element could be found · exception pywinauto.findwindows.WindowAmbiguousError¶ · There was more then one window that matched · exception pywinauto.findwindows.WindowNotFoundError¶ · No window could be found ·
🌐
GitHub
github.com › pywinauto › pywinauto › issues › 1008
Pywinauto hangs and exits with pywinauto.findwindows.ElementNotFoundError if there is a long List · Issue #1008 · pywinauto/pywinauto
import ctypes import re import pywinauto from pywinauto import findwindows, Application from pywinauto.timings import Timings from pywinauto.win32structures import RECT if __name__ == '__main__': wins = findwindows.find_windows(title_re=".*Darwinex") Timings.window_find_timeout = 300 if len(wins) <= 0: raise Exception("Darwinex no está activo, tío.") else: app: Application = pywinauto.application.Application(backend="uia", allow_magic_lookup=False) app.connect(title_re=r".*Darwinex", control_type="Window") print('app-> ', app.top_window().child_window(title='Probador', top_level_only=True).dump_tree(), flush=True)
🌐
Stack Overflow
stackoverflow.com › questions › 62519676 › pywinauto-findwindows-elementnotfounderror-element-is-available-in-the-screen
python - pywinauto.findwindows.ElementNotFoundError:- Element is available in the screen when scrolling down/up - Stack Overflow
dealerName.set_text("Car Dealer") File "C:\Python\Python37\lib\site-packages\pywinauto\application.py", line 379, in __getattribute__ ctrls = self.__resolve_control(self.criteria) File "C:\Python\Python37\lib\site-packages\pywinauto\application.py", line 261, in __resolve_control raise e.original_exception File "C:\Python\Python37\lib\site-packages\pywinauto\timings.py", line 436, in wait_until_passes func_val = func(*args, **kwargs) File "C:\Python\Python37\lib\site-packages\pywinauto\application.py", line 222, in __get_ctrl ctrl = self.backend.generic_wrapper_class(findwindows.find_element(*
🌐
Readthedocs
pywinauto-docs.readthedocs.io › en › docs-rework › code › pywinauto.findwindows.html
pywinauto.findwindows — pywinauto 0.5.4 documentation
exception pywinauto.findwindows.ElementNotFoundError¶ · No element could be found · exception pywinauto.findwindows.WindowAmbiguousError¶ · There was more then one window that matched · exception pywinauto.findwindows.WindowNotFoundError¶ · No window could be found ·
🌐
Readthedocs
pywinauto-fork.readthedocs.io › en › latest › code › pywinauto.findwindows.html
pywinauto.findwindows — pywinauto 0.6.5 documentation
exception pywinauto.findwindows.ElementNotFoundError¶ · No element could be found · exception pywinauto.findwindows.WindowAmbiguousError¶ · There was more then one window that matched · exception pywinauto.findwindows.WindowNotFoundError¶ · No window could be found ·
🌐
GitHub
github.com › pywinauto › pywinauto › issues › 993
child_window raises ElementNotFoundError on element can be displayed by print_control_identifiers · Issue #993 · pywinauto/pywinauto
October 15, 2020 - >>> txb_custom.child_window(title="PET ...find_element(**ctrl_criteria)) File "C:\Program Files\Python38\lib\site-packages\pywinauto\findwindows.py", line 87, in find_element raise ElementNotFoundError(kwargs) pywinauto.findwindows.ElementNotFoundError: {'title': 'PET WB', 'auto_id': ...
Author   simohauml
Find elsewhere
🌐
Readthedocs
airelil-pywinauto.readthedocs.io › en › latest › code › pywinauto.findwindows.html
pywinauto.findwindows — pywinauto 0.6.6 documentation
exception pywinauto.findwindows.ElementNotFoundError¶ · No element could be found · exception pywinauto.findwindows.WindowAmbiguousError¶ · There was more then one window that matched · exception pywinauto.findwindows.WindowNotFoundError¶ · No window could be found ·
🌐
GitHub
github.com › pywinauto › pywinauto › issues › 1231
Element Not Found · Issue #1231 · pywinauto/pywinauto
July 25, 2022 - When I tried clicking it gave me an error pywinauto.findwindows.ElementNotFoundError: {'title': 'Menu Search', 'control_type': 'MenuItem', 'top_level_only': False, 'parent': <uia_element_info.UIAElementInfo - 'proddb: AU Australasia [AUD] > 325 Ingleburn - Manufacturng (1) - QAD Enterprise Applications ', WindowsForms10.Window.8.app.0.83a9e6_r9_ad1, 44040818>, 'backend': 'uia'}
🌐
GitHub
github.com › pywinauto › pywinauto › issues › 268
cannot get the child controls · Issue #268 · pywinauto/pywinauto
November 17, 2016 - File "C:\usr\work\SAPScript\pywinauto\test_pywinauto.py", line 38, in <module> pywinauto.findwindows.find_element(control_id=child.control_id()).draw_outline() File "c:\usr\Python27\lib\site-packages\pywinauto\findwindows.py", line 87, in find_element raise ElementNotFoundError(kwargs) pywinauto.findwindows.ElementNotFoundError: {'control_id': 92062304} Any idea on what's wrong with my code or any workaround to get the controls?
Author   hastelloy
🌐
GitHub
github.com › pywinauto › pywinauto › issues › 1070
ElementNotFoundError error in connect api at self.process = findwindows.find_element(**kwargs).process_id · Issue #1070 · pywinauto/pywinauto
May 16, 2021 - ElementNotFoundError error in connect api at self.process = findwindows.find_element(**kwargs).process_id #1070 ... There is this pywinauto script on a remote host which is aimed at connecting to the VPN client gui. The script executes fine when executed locally on the remote host.
Published   May 16, 2021
Author   poornima55
🌐
GitHub
github.com › pywinauto › pywinauto › issues › 1078
Question - Pywinauto support for Microsoft edge browser application · Issue #1078 · pywinauto/pywinauto
May 26, 2021 - Traceback (most recent call last): File "C:\Users\cisco\edge.py", line 19, in ext = me_app.connect(title='.New tab.') File "C:\Users\cisco\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\application.py", line 997, in connect self.process = findwindows.find_element(**kwargs).process_id File "C:\Users\cisco\AppData\Local\Programs\Python\Python39\lib\site-packages\pywinauto\findwindows.py", line 87, in find_element raise ElementNotFoundError(kwargs) pywinauto.findwindows.ElementNotFoundError: {'title': '.New tab.', 'backend': 'uia', 'visible_only': False} Run the code snippet f
Published   May 26, 2021
Author   poornima55
🌐
GitHub
github.com › pywinauto › pywinauto › issues › 736
Pywinauto doesn't see most of controls while connecting to Skype · Issue #736 · pywinauto/pywinauto
May 19, 2019 - Traceback (most recent call last): ... File "C:\Users\Bravissimo\AppData\Local\conda\conda\envs\py36\lib\site-packages\pywinauto\findwindows.py", line 87, in find_element raise ElementNotFoundError(kwargs) pywinauto.findwindows.ElementNotFoundError: {'title_re': 'Skype.*', 'backend': ...
Published   May 19, 2019
Author   dstepanenko
🌐
Python Forum
python-forum.io › thread-39578.html
Help ~ coding with pywinauto
March 12, 2023 - hi i would like automate the windows task using pywinauto for my VPN i am getting an issue to detect the element properly and access the element some dont not have automation ID / name / title , some have ambigious (more than 1 element) with same...
🌐
GitHub
github.com › pywinauto › pywinauto › issues › 349
ListItem ElementNotFoundError · Issue #349 · pywinauto/pywinauto
May 2, 2017 - pywinauto.findwindows.ElementNotFoundError: {'top_level_only': False, 'title_re': 'High', 'parent': <pywinauto.uia_element_info.UIAElementInfo object at 0x00A819D0>, 'backend': 'uia'} Is there known reason why this is happening? Is there another way how to select ListBox item?
🌐
GitHub
github.com › pywinauto › pywinauto › issues › 603
Element Not found error while installing · Issue #603 · pywinauto/pywinauto
November 14, 2018 - Traceback (most recent call last): File "C:/Users/Administrator/Desktop/Raja python/python practice/click_install.py", line 10, in <module> b = Application().connect(title = 'Git 2.9.3.2 Setup') File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pywinauto-0.6.5-py3.7.egg\pywinauto\application.py", line 965, in connect self.process = findwindows.find_element(**kwargs).process_id File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pywinauto-0.6.5-py3.7.egg\pywinauto\findwindows.py", line 87, in find_element raise ElementNotFoundError(kwargs) pywinauto.findwindows.ElementNotFoundError: {'title': 'Git 2.9.3.2 Setup', 'backend': 'win32'} Thanks, raja ·