Nick
Nick

Reputation: 675

pywinauto find an exact tray item

I'm trying to create an automated GUI test framework for a desktop application and I am using pywinauto for this. My problem is that even using SWAPY and Winspector I still have problems detecting the tray area and finding my app there.

I have tried everything from the current documentation and also tried the Volume example from the web to no success.

from pywinauto import taskbar

sti = taskbar.SystemTrayIcons.WrapperObject()

print 'Clicking ', sti.Button(0).info.text
sti.Button(0).Click()

Technically the only thing i need is finding the exact position of the tray icon and executing a click on it to bring up a menu.

pywinauto has some functions related to the taskbar but i wasn't able to get them to work.

Could anybody give me any ideas on how to do this?

EDIT

I tried your idea Vasily but I am getting this error:

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

and the traceback:

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

I'm using Windows 7 Pro x64 right now but I need this to also run on 8, 8.1 and 10 (I can drop 10 since I imagine support for it is still behind)

Upvotes: 1

Views: 3495

Answers (1)

Vasily Ryabov
Vasily Ryabov

Reputation: 9991

If you use pywinauto 0.5.1, please call taskbar.SystemTrayIcons.Texts() and then copy corresponding text to the following call:

taskbar.ClickSystemTrayIcon('button text', exact=True, double=True)

For hidden area use ClickHiddenSystemTrayIcon(...).

Also please note that popup menu belongs to your application process. So you need to connect to the application and call app.PopupMenu.MenuItem('item name').Click() or ClickInput().

If it doesn't work, please provide error output and OS version.

EDIT:

(comment about Python 32/64 bit problem)

Ideal way is running taskbar specific code in 64-bit Python and then launching 32-bit Python for separate app specific script. It's not so convenient but should work.

Upvotes: 0

Related Questions