我正在尝试为桌面应用程序创建一个自动化的 GUI 测试框架,为此我正在使用 pywinauto。我的问题是,即使使用 SWAPY 和 Winspector,我仍然无法检测托盘区域并在那里找到我的应用程序。
我已经尝试了当前文档中的所有内容,还尝试了网络上的 Volume 示例,但没有成功。
from pywinauto import taskbar
sti = taskbar.SystemTrayIcons.WrapperObject()
print 'Clicking ', sti.Button(0).info.text
sti.Button(0).Click()
从技术上讲,我唯一需要的是找到托盘图标的确切位置并单击它以显示菜单。
pywinauto 有一些与任务栏相关的功能,但我无法让它们工作。
有人能给我关于如何做到这一点的任何想法吗?
编辑
我尝试了您的 Vasily 想法,但出现此错误:
import pywinauto
from pywinauto import taskbar
app = pywinauto.application.Application()
app.start_('C:\Program Files (x86)\MyApp.exe')
w_handle = pywinauto.findwindows.find_windows(title=u'MyApp')[0]
window = app.window_(handle=w_handle)
texts = taskbar.SystemTrayIcons.Texts()
print texts
和回溯:
Traceback (most recent call last):
File "C:/Users/nicolae.farcas/Desktop/pywinauto_c1.py", line 9, in <module>
texts = taskbar.SystemTrayIcons.Texts()
File "C:\Python27\lib\site-packages\pywinauto\controls\common_controls.py", line 1932, in Texts
btn_text = self.GetButton(i).text
File "C:\Python27\lib\site-packages\pywinauto\controls\common_controls.py", line 1914, in GetButton
button.idCommand)
RuntimeError: GetButtonInfo failed for button with command id 0
我现在正在使用 Windows 7 Pro x64,但我需要它也可以在 8、8.1 和 10 上运行(我可以放弃 10,因为我认为对它的支持仍然落后)