PyWinAuto select 文件 -> 从 Tableau Desktop 打开

PyWinAuto select File -> Open from Tableau Desktop

我正在尝试使我们已有的流程中的几个步骤自动化。与画面交互需要 2 个步骤,我只想按下这些按钮。

我遵循 pywinauto 文档提供的记事本示例,但是当我尝试 select 子菜单选项时,它总是失败。

dlg.menu_select('File') 有效

dlg.menu_select('File -> Open') 无效

dlg.menu_select('File -> Open...') 无效

TimeoutError:超时

# Using .Server because .File gives me pdf info. Still a menu item.
dlg.Server.print_control_identifiers()

控件标识符:

静态 - 'To a Server'(L165、T685、R403、B711) ['To a ServerStatic'、'Static'、'To a Server'] child_window(title="到服务器", control_type="文本")

我也找不到文件菜单项,所以我最终使用了控制字符。

import time
from pywinauto.application import Application
from pywinauto.keyboard import send_keys
from pywinauto.controls.menuwrapper import Menu, MenuItemInfo
from pywinauto import mouse

import win32api

send_keys('^o') # open file

send_keys('C:\Users\xxx\Pareto.twbx', with_spaces = True)  # absolute file name

send_keys('{VK_RETURN}')  # accept file

updatedata = dlg.TableauPareto.child_window(title="Data Alt+D", control_type="MenuItem").wrapper_object()
updatedata.click_input() # open menu

x, y = win32api.GetCursorPos()  # find cursor position
mouse.click(button='left', coords=(x+ 30, y+85)) # click on refresh data

send_keys('{VK_RETURN}') # refresh data

time.sleep(10) # wait for refresh

send_keys('{VK_RETURN}') # end
send_keys('^s')  # save file

app.kill(soft=False) # quit