Hi Ranorex,
I'm having trouble finding the context menu of our applications' tray icon.
I'm able to get the element of the icon, but the icon has 0 children elements.
I have tried:
Using the Ranorex.ContextMenu class - it doesn't find the context menu of the icon
Right clicking on the icon and using Control.SendKeys - Control.SendKeys sends only to the primary application
Using the task tray as it's own form and using Application.SendKeys
any tips you could provide would be very appreciated
TIA,
cmiller
Navigating task tray icon context menus
Please read the post:
Trouble accessing Windows notification tray area.
(It's a Python sample in the reply for using the contexmenu of the Touch Pad, but you can do the same in C# with your application' tray icon.)
Please post your C# code here if it works.
Jenö
Trouble accessing Windows notification tray area.
(It's a Python sample in the reply for using the contexmenu of the Touch Pad, but you can do the same in C# with your application' tray icon.)
Code: Select all
hTaskTray = Ranorex.FormFindClassName("Shell_TrayWnd", 1, True, 5000)
trayElement = Ranorex.ControlGetElement(hTaskTray)
notifyElement = Ranorex.ElementFindChild(trayElement, Ranorex.ROLE_SYSTEM_CLIENT, "", 'TrayNotifyWnd')
touchButton = Ranorex.ElementFindChild(notifyElement,Ranorex.ROLE_SYSTEM_PUSHBUTTON, 'Touch Pad')
if touchButton == None:
print 'Touch button not found'
return 1
Ranorex.MouseClickElement(touchButton,Ranorex.MOUSE_RIGHT_BUTTON)
Ranorex.Sleep(100)
Ranorex.ContextMenuSelectItemText('&Info')
Jenö
Thank you for the code snippet, I converted it to C# but it is not working.
The ContextMenu.SelectItemText returns error -3.
As an exception the error is "The specified command could not be executed."
The ContextMenu.SelectItemText returns error -3.
As an exception the error is "The specified command could not be executed."
Code: Select all
Form hTaskTray = Ranorex.Application.FindFormClassName("Shell_TrayWnd", 1 , true, 5000);
Element trayElement = hTaskTray.Element;
Element touchButton = trayElement.FindChild(Role.PushButton, "RanorexSpy");
if (null == touchButton)
{
Logging.WriteToLog("Could not find icon");
return Data.Result.FATAL;
}
Ranorex.Mouse.ClickElement(touchButton, Ranorex.MouseButtonType.RightButton);
Ranorex.Application.Sleep(100);
int error = Ranorex.ContextMenu.SelectItemText("About ...") ; //Returns error -3
The code works for me, but the menu text has two spaces, between About and ...
(Don't ask me why, it's a cosmetic error)
Please use a & symbol if your menu text has a shortcut key.
Jenö
Code: Select all
int error = Ranorex.ContextMenu.SelectItemText("About ...");
Please use a & symbol if your menu text has a shortcut key.
Jenö
Thank you for all the help, I'm able to navigate RanorexSpy now, but still having trouble with other icons.
I'm not able to GetItemText, SelectItemText or SelectPosition either of the two options in the Volume icon tray which controls the volume in windows XP.
I'm not able to GetItemText, SelectItemText or SelectPosition either of the two options in the Volume icon tray which controls the volume in windows XP.
Code: Select all
Form hTaskTray = Ranorex.Application.FindFormClassName("Shell_TrayWnd", 1 , true, 5000);
Element trayElement = hTaskTray.Element;
Element touchButton = trayElement.FindChild(Role.PushButton, "Volume");
if (null == touchButton)
{
Logging.WriteToLog("Could not find icon");
return Data.Result.FATAL;
}
Ranorex.Mouse.ClickElement(touchButton, Ranorex.MouseButtonType.RightButton);
Ranorex.Application.Sleep(1000);
string name = null;
int position = 2;
name = Ranorex.ContextMenu.GetItemText(position);
int error = Ranorex.ContextMenu.SelectPosition(position);
We have released a new version V1.1.0 today.
I used this new version yesterday and it worked for both RanorexSpy and VolumeControl. We fixed a bug in the ContextMenu core and i think this version will also work with your application.
Please download, try the new version and inform us about the results.
Jenö
I used this new version yesterday and it worked for both RanorexSpy and VolumeControl. We fixed a bug in the ContextMenu core and i think this version will also work with your application.
Please download, try the new version and inform us about the results.
Jenö