Sunday, April 22, 2012

Select element in system tray (Windows 7) using WDTP

There was a question from my colleague, how do I select an element from system tray icon in Windows 7 using windtp. I came up with the following code:

from ldtp import *
s=getobjectsize('pane0', 'btnNotificationChevron')
generatemouseevent(s[0] + s[2]/2, s[1] + s[3]/2, 'b1c')
s1=getobjectsize('paneNotificationOverflow', 'btnMcAffee*')
generatemouseevent(s1[0] + s1[2]/2, s1[1] + s1[3]/2, 'b3c')
selectmenuitem('mnuContext', 'mnuVirusScanConsole')

He asked me how do get to identify these objects, when I use UI Automation Verify, I could not identify the object as the icon in sys tray disappears after I select something in the tool.

I explained him this what I did to find the object in a python prompt:

First used getojbectlist('pane0') to verify whether its the bottom panel and noticed 'Start' button was part of the output.
Tried clicking all the objects one by one in the tray icon to see which one has all the hidden app icons and found 'Notification Chevron' button.
He asked me why do you use s[0] + s[2] / 2 ... I explained as: to click on the center of the widget, get the object size (x, y, width, height) then do x + width / 2, y + height / 2 and get the center point on the object and do left click (b1c).
Once the app icons popup do right click on the object, which pops up the menu.
Next question from him was, how did you found 'mnuContext' as the window name ?
I did getwindowlist() before right clicking the object and after that as well, with that I found one additional window name in the list which is 'mnuContext'.

Now you are all set for selecting the element from sys tray icon.


At Monday, April 30, 2012 at 6:13:00 AM PDT, Blogger Justin A said...

(x,y,width,height) = getobjectsize('pane0', 'btnNotificationChevron')

generatemouseevent(x + width/2, y + height/2, 'b1c')


Post a Comment

<< Home