【发布时间】:2016-02-22 17:10:21
【问题描述】:
我正在尝试为桌面应用程序创建一个自动化的 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,因为我认为对它的支持仍然落后)
【问题讨论】:
-
你在 64 位 Python 上使用 pywinauto 0.5.1 吗?
-
不,我用的是 32 位的
-
进程
explorer.exe包含任务栏在 64 位操作系统上是 64 位的。您需要 64 位 Python。我会考虑任务栏模块中的警告。 -
您是否在脚本输出中看到有关不正确位数的警告?
-
我有时会看到如下警告:警告!无法检索句柄的文本长度 = 198548 警告!无法检索句柄的文本长度 = 66940 警告!无法检索句柄 = 131878 的文本长度