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

别来无恙 提交于 2019-12-11 03:56:28

问题


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.


回答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.



来源:https://stackoverflow.com/questions/33113913/pywinauto-menuselect-cannot-be-used-to-select-menubar-in-some-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!