我创建了一个简单的VB .NET(32位)程序。该应用程序的菜单有3个菜单项:"退出","新"和"关于"。我想选择" New"菜单项但我收到错误。错误是没有菜单。我确实打印了控件标识符。它们在这里展示。
Control Identifiers:
WindowsForms10.Window.8.app.0.141b42a_r9_ad1 - 'b'MenuStrip1'' (L86, T109,
R370, B133)
'b'MenuStrip1''
'b'MenuStrip1WindowsForms10.Window.8.app.0.141b42a_r9_ad1''
'b'WindowsForms10.Window.8.app.0.141b42a_r9_ad1''
Traceback (most recent call last):
File "C:\Python Scripts\TestVBApp3.py", line 21, in <module>
app.MenuStrip.MenuSelect("New")
File "C:\Users\lyle.lacey\AppData\Local\Programs\Python\Python35-
32\lib\site-packages\pywinauto\controls\HwndWrapper.py", line 1385, in
MenuSelect
self.MenuItem(path, exact=exact).Select()
File "C:\Users\lyle.lacey\AppData\Local\Programs\Python\Python35-
32\lib\site-packages\pywinauto\controls\HwndWrapper.py", line 1337, in
MenuItem
raise RuntimeError("There is no menu.")
RuntimeError: There is no menu.
以下是代码(我使用的是Visual Studio 2015社区版):
from pywinauto.application import Application
from time import sleep
import pyautogui
pyautogui.FAILSAFE = True
app = Application().Start(cmd_line=u'"C:\\VBPrograms\\MenuStrip.exe"')
app.MenuStrip.Wait('ready')
app.MenuStrip.PrintControlIdentifiers()
app.MenuStrip.MenuSelect("New")
sleep(5)
app.MenuStrip.Close()
注意:我使用的是Python 3.5,pywinauto 0.5.4,Visual Studio 2015社区版(VB .NET for App)。
感谢您的帮助!!
-Lyle