首页 > 解决方案 > 使用 RPA 从 Power BI 桌面窗口组件中获取的自动化 ID 为空

问题描述

我正在尝试使用 RPA.Desktop.Windows 中的 rpaframework 库获取所有 Power BI 桌面组件但是对于大多数Power BI 窗口组件,返回的automation_id为空。显示了下面我得到的几个窗口组件的结果,例如CloseGetdata

([<uia_controls.StaticWrapper - 'Get data', Static, 8881667776078132027>,
<uia_controls.ButtonWrapper - 'Close', Button, -4781744411977329195>], [{'automation_id': '', 
'class_name': '', 'control_id': 'None', 'control_type': 'Text', 'enabled': 'True', 'handle': 
'None', 'name': 'Get data', 'parent': 'Button', 'process_id': '10844', 'rectangle': '(L195, T241, 
R255, B261)', 'rich_text': 'Get data', 'runtime_id': '(42, 133602, 4, 842, 61453, 1)', 'visible':
 'True', 'legacy': {'ChildId': 1, 'DefaultAction': '', 'Description': '', 'Help': '', 
'KeyboardShortcut': '', 'Name': 'Get data', 'Role': 42, 'State': 64, 'Value': ''}, 'object': 
<uia_controls.StaticWrapper - 'Get data', Static, 8881667776078132027>}, {'automation_id': '',
 'class_name': '', 'control_id': 'None', 'control_type': 'Button', 'enabled': 'True', 'handle': 
'None', 'name': 'Close', 'parent': 'Pane', 'process_id': '10844', 'rectangle': '(L1200, T73, 
R1232, B99)', 'rich_text': 'Close', 'runtime_id': '(42, 133602, 4, 855)', 'visible': 'True', 
'legacy': {'ChildId': 0, 'DefaultAction': 'Toggle', 'Description': '', 'Help': '', 
'KeyboardShortcut': '', 'Name': 'Close', 'Role': 43, 'State': 1048576, 'Value': ''}, 'object': 
<uia_controls.ButtonWrapper - 'Close', Button, -4781744411977329195>}])

我也检查了Accessibility Insights For Windows,它显示属性不存在key AutomationId的值。适用于 Power BI 的 Windows 的可访问性见解

而且因为automation_id为空,我正在使用键访问每个power bi窗口元素,因此在访问元素时出现错误,因为raise ValueError(f"Could not find unique element for '{locator}'") ValueError: Could not find unique element for 'name:'Close' and control_type:Button'

附上我尝试使用 RPA的Power BI 桌面自动化的以下代码

from RPA.Desktop.Windows import Windows
import time

win = Windows()
print(win)
def open_powerBI():
    win.open_from_search("PBIDesktop","Untitled - Power BI Desktop",120)
    time.sleep(10)
    first_window_elements = win.get_window_elements()
    print(first_window_elements)
    win.mouse_click("name:'Close' and control_type:Button")

if __name__ == "__main__":
    open_powerBI()

我也尝试过使用 计算器应用程序进行自动化,我得到了所有计算器应用程序组件的automation_id值,如下所示,我能够执行自动化。

([<uia_controls.ButtonWrapper - 'Minus', Button, -1856622049320485851>, <uia_controls.ButtonWrapper - 'One', Button, 2312570849329984554>], [{'automation_id': 'minusButton', 'class_name': 'Button', 'control_id': 'None', 'control_type': 'Button', 'enabled': 'True', 'handle': 'None', 'name': 'Minus', 'parent': 'Group', 'process_id': '7528', 'rectangle': '(L754, T446, R830, B498)', 'rich_text': 'Minus', 'runtime_id': '(42, 197882, 4, 42)', 'visible': 'True', 'legacy': {'ChildId': 0, 'DefaultAction': 'Press', 'Description': '', 'Help': '', 'KeyboardShortcut': '', 'Name': 'Minus', 'Role': 43, 'State': 1048576, 'Value': ''}, 'object': <uia_controls.ButtonWrapper - 'Minus', Button, -1856622049320485851>},{'automation_id': 'num1Button', 'class_name': 'Button', 'control_id': 'None', 'control_type': 'Button', 'enabled': 'True', 'handle': 'None', 'name': 'One', 'parent': 'Group', 'process_id': '7528', 'rectangle': '(L519, T500, R595, B552)', 'rich_text': 'One', 'runtime_id': '(42, 197882, 4, 51)', 'visible': 'True', 'legacy': {'ChildId': 0, 'DefaultAction': 'Press', 'Description': '', 'Help': '', 'KeyboardShortcut': '', 'Name': 'One', 'Role': 43, 'State': 1048576, 'Value': ''}, 'object': <uia_controls.ButtonWrapper - 'One', Button, 2312570849329984554>}])

关于 Power BI 桌面为什么返回的automation_id的任何建议都是空的,关于为什么我无法访问窗口组件的建议将很有帮助。

标签: pythonautomationpowerbipowerbi-desktoprpa

解决方案


推荐阅读