'Pywinauto - There are 2 elements that match criteria

this is my first post! I would like to ask you how can i solve this problem. I am trying to automate publish in powerBI. I need to click on correct workspace. Right now i am trying with " My workspace" which is there only once. Please check this image of PowerBI window

This is screen from inspect.exe

part of python code looks like this:

win = app.window(title_re = '.*Power BI Desktop')
win.Publish.click_input()
publish_dialog = win.child_window(auto_id = "KoPublishToGroupDialog")
publish_dialog.child_window(title = "My Workspace").click_input()
publish_dialog.Select.click()

Error msg looks like this

There are 2 elements that match the criteria {'title': 'My workspace', 'top_level_only': False, 'parent': <uia_element_info.UIAElementInfo - 'Publish to Power BI', WindowsForms10.Window.20008.app.0.3c73ab4_r6_ad1, 667196>, 'backend': 'uia'}

Can somebody explain me what is problem and how can i solve this?

Additional info from inspect.exe

Thank you very much



Solution 1:[1]

You can choose which element to find:

child_window(title="My Workspace", found_index=0) # or found_index=1

Using control_type is also desired because it makes search faster.

Solution 2:[2]

This works for me:

dlg.Publish.click_input()
dlg.child_window(title="My workspace", control_type="DataItem", found_index=0).click_input()
dlg.Select.click()

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 Vasily Ryabov
Solution 2 D. Schreier