TAGS :Viewed: 5 - Published at: a few seconds ago

[ pywinauto: MenuSelect() Cannot be used to select "MenuBar" in some applications. What is a suitable function from this library to use? ]

I automate tests for an application called "Team Developer" belongs to Gupta Technology. It has a Menu bar not a menu. I'm not able to select the menu by MenuSelect(), and it shows "raise RuntimeError("There is no menu.")" error.

import pywinauto
import time

from pywinauto.application import Application
app = Application.start('C:\Program Files (x86)\Gupta\Team Developer.exe')
pywinauto.application.Application()
time.sleep(2)
MenuItms = app.window_(title_re = "Gupta*").MenuSelect("File->Exit")

How can I select an Item from menu bar? I also have used "Swapy" to get the correct python code for pywinauto, but no useful results.

Answer 1


Menu bar can be re-interpreted as a toolbar now. Button texts are not available though (it can be done using mixed native/UIA approach much later). You can try latest branch of pywinauto (run python setup.py install).

This is an example with RebarTest.exe sample app (running from the repo root folder):

import pywinauto

app = pywinauto.Application().start_(r'.\apps\MFC_samples\x64\RebarTest.exe')
app.RebarTest.MenuBar.MenuBarClickInput('#1->#0->#0', app) # View->Toolbars->Customize
app.Customize.CloseButton.Click()
app.Customize.WaitNot('visible')

app.RebarTest.MenuBar.MenuBarClickInput([2, 0], app)
app.Window_(title='About RebarTest').OK.Click()
app.Window_(title='About RebarTest').WaitNot('visible')

Please try this workaround for your app and let us know if it works.