'"there are 2 elements that match the criteria" error in Spyder IDE

Goal: I'm trying to automate Canva.exe to create designs via GUI automation.

Specs: Spyder V5 (via anaconda) and Python 3.8 on Windows 11 Home OS

Problem: pywinauto is finding duplicate target values for the last 2 lines of my code (below) and giving me the error message (also included below).

Code:

import time
from pywinauto.application import Application 

CanvaWin = Application(backend='uia').connect(title='Canva', timeout=100) 
#CanvaWin.Canva.print_control_identifiers()

YP = CanvaWin.Canva.child_window(title="Your projects",control_type="Text").wrapper_object()
YP.click_input()


UP = CanvaWin.Canva.child_window(title="Uploader", control_type="Text").wrapper_object()
UP.click_input()


VT = CanvaWin.Canva.child_window(title="1 OF 2 More actions VideoTemplate Presentation", control_type="Button").wrapper_object()
VT.click_input()

time.sleep(10)

#CanvaWin.Canva.print_control_identifiers()

ETT = CanvaWin.Canva.child_window(title="enter title", control_type="Text").wrapper_object()
ETT.click_input()

Error Message:

ElementAmbiguousError: There are 2 elements that match the criteria {'title': 'enter title', 'control_type': 'Text', 'top_level_only': False, 'parent': <uia_element_info.UIAElementInfo - 'Canva', Chrome_WidgetWin_1, 198500>, 'backend': 'uia'}


Solution 1:[1]

In case of multiple elements matching your criteria, you can select one of them by adding found_index parameter to child_window-method:

ETT = CanvaWin.Canva.child_window(title="enter title", control_type="Text", found_index=0).wrapper_object()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 juhat