Pywinauto - There are 2 elements that match criteria

11k Views Asked by At

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

2

There are 2 best solutions below

0
On BEST ANSWER

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.

0
On

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()