python - 使用 RPA 从 Power BI 桌面窗口组件中获取的自动化 ID 为空
问题描述
我正在尝试使用 RPA.Desktop.Windows 中的 rpaframework 库获取所有 Power BI 桌面组件,但是对于大多数Power BI 窗口组件,返回的automation_id为空。显示了下面我得到的几个窗口组件的结果,例如Close和Getdata。
([<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的任何建议都是空的,关于为什么我无法访问窗口组件的建议将很有帮助。
解决方案
推荐阅读
- arrays - Google 表格创建 IF 或 IFS
- mapreduce - CouchDB 视图每个键减少一个文档
- entity-framework-core - Entity Framework Core Cosmos DB 提供程序的 Guid 分区键
- python - 如何使用 python 读取绘图和提取信息
- c++ - 不懂迭代器、引用和指针失效,一个例子
- deep-learning - 使用 keras 对多类图像分割中的样本进行加权
- reactjs - Heroku:如何在部署之前添加 .env 文件中的变量?
- javascript - 如何在从 html 中单击时运行 java 方法?
- git - 如何使用 GitHub Actions SCP 存储库文件?
- jenkins - 在 Jenkinsfile 中解析 shell 脚本以进行测试