Pywinauto关注新下拉列表

2024-04-23 16:26:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试在powerbi中根据特定的参数自动刷新数据。为了调整powerbi刷新脚本(https://github.com/dubravcik/pbixrefresher-python),基于PyWinAuto。 为了调整参数,我必须在PowerBI的功能区打开并使用一个下拉菜单,我怀疑在打开下拉菜单时,焦点仍然在PowerBI的主屏幕上,因此我无法在下拉菜单内进行操作。在

我如何识别和集中在下拉菜单与PyWinAuto?在

(另见https://i.imgur.com/pbFmMJa.png

# Focus on the Power BI window
app = Application(backend = 'uia').connect(path = PBIDesktop.exe)
win = app.window(title_re = '.*Power BI Desktop')
win.wait("enabled", timeout = 300)
win.set_focus()
win.wait("enabled", timeout = 300)

# Open the dropdown menu with Alt+H, then Q
win.type_keys('%HQ')
# Next part doesn't work, I suspect because of no focus on the dropdown menu
win.type_keys('{DOWN}{DOWN}{ENTER}')

Tags: thehttpscomapp参数onwindowwin