I'm trying to automate a few steps in a process we have. There are 2 steps that I need to interact with tableau, I just want to press these buttons.
I follow the Notepad example that the pywinauto docs provide, but when I try to select a sub menu option, it keep failing.
dlg.menu_select('File')
works
dlg.menu_select('File -> Open')
doesn't work
dlg.menu_select('File -> Open...')
doesn't work
TimeoutError: timed out
# Using .Server because .File gives me pdf info. Still a menu item.
dlg.Server.print_control_identifiers()
Control Identifiers:
Static - 'To a Server' (L165, T685, R403, B711) ['To a ServerStatic', 'Static', 'To a Server'] child_window(title="To a Server", control_type="Text")
I couldn't find the file menu items either so I ended up using control characters.
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