PopUp menu not recognized

Class library usage, coding and language questions.
prashantb
Posts: 9
Joined: Thu Aug 23, 2007 3:59 pm

PopUp menu not recognized

Post by prashantb » Thu Oct 25, 2007 10:45 am

Hi,
I am evaluating RanoRex for Visual Studio 2005 Add-in. The add-in will add some context menus to the standard context menu of Visual Studio 2005. I am using following code to select the context menu, but Ranorex gives -1 error.


if Ranorex.MouseClickElement(element, Ranorex.MOUSE_RIGHT_BUTTON) != 0:
return 1
Ranorex.Sleep(1000);

# Test Contextmenu select item text
ret = Ranorex.ContextMenuSelectItemText('Test with','.NET');
if ret != 0:
print 'Error: ContextMenuSelectItemText(Test with, .NET) ' + str(ret);
return 8;


I have also tried to record using RanoRex recorder but while playing back the script it gets hanged.

The Class of pop up menu is 'MSOCommandBarPopup'

Please let me know how I can select the context menu.
Regards,
Prashant Barhate

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Thu Oct 25, 2007 9:47 pm

Please let me know how I can select the context menu.
The following sample opens a contextmenu in the SolutionExplorer of VS and clicks the Properties menu item:

Code: Select all

Form form = Application.FindFormTitle("Microsoft Visual Studio", 
            SearchMatchMode.MatchSubstring,true);
Control solutionExplorer = form.FindChildText("Solution Explorer");
Mouse.ClickControl(solutionExplorer, MouseButtonType.RightButton);
Application.Sleep(200);
Form contextMenuWindow = Application.FindForm("Project", 
            SearchMatchMode.MatchFromStart, "MsoCommandBarPopup");
Element properties = contextMenuWindow.Element.FindChild(Role.MenuItem, "Properties");
Mouse.ClickElement(properties);
You should search the context menu in the top level with Application.FindForm();

Jenö
Ranorex Team

prashantb
Posts: 9
Joined: Thu Aug 23, 2007 3:59 pm

Post by prashantb » Mon Oct 29, 2007 9:28 am

Thanks Jeno
I have used code sample mentioned by you. But still it could not select the menu item.
I have checked the children item count and it has given me 7 for the popup menu. But actually there are 10 menu items. Then I checked the description (tuple) of each child item. Ranorex recognize its child as "MSOCommandBarShadow". These objects are nothing but the menu separators which holds menu item and there are 7 section in the menu item.

Can you please tell me how I can select these menu items?
Regards,
Prashant Barhate

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Mon Oct 29, 2007 6:26 pm

Can you please post us the source code of your test application.
We will check it with visual studio.

Jenö
Ranorex Team

prashantb
Posts: 9
Joined: Thu Aug 23, 2007 3:59 pm

Post by prashantb » Tue Oct 30, 2007 12:40 pm

Hi Jeno,
This problem is not specific due to our Test Application. It is not working even without any add-in in Visual Studio. To reproduce the exact scenario, create a C# windows application project and check for "Properties" menu item.

I have debugged the script using your code. But it is returning null while finding element of Role MenuItem.
Regards,
Prashant Barhate

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Tue Oct 30, 2007 2:23 pm

The caption of the context menu depends on the element you perform the right click on. So you have to click on the right element in the solution explorer to find a context menu with a particular caption.

The following code sample right clicks on the first tree view item in the solution explorer. This opens a context menu which caption is "Solution". And then you can search for this contextmenu by the specified caption.

Code: Select all

Form form = Application.FindFormTitle("Microsoft Visual Studio",
SearchMatchMode.MatchSubstring, true);
Control solutionExplorer = form.FindChildText("Solution Explorer");
Element solutionElement = solutionExplorer.Element.FindChild(Role.OutlineItem);
Mouse.ClickElement(solutionElement, MouseButtonType.RightButton);
Application.Sleep(200);
Form contextMenuWindow = Application.FindForm("Solution",
            SearchMatchMode.MatchFromStart, "MsoCommandBarPopup");
Element properties = contextMenuWindow.Element.FindChild(Role.MenuItem, "Properties");
Mouse.ClickElement(properties);
Regards,

Alex
Ranorex Support Team

prashantb
Posts: 9
Joined: Thu Aug 23, 2007 3:59 pm

Post by prashantb » Wed Oct 31, 2007 7:01 am

Hi Alex,
I agree with you that Caption of context menu depends on the item selected in the solution explorer. If you click on solution file, the caption will be "Solution". For project file the caption will be "Project" and for any item inside the project the caption will be "Item". I have already checked with that but still it gives null while finding the child element of Role Menu Item.
Regards,
Prashant Barhate

prashantb
Posts: 9
Joined: Thu Aug 23, 2007 3:59 pm

Post by prashantb » Wed Oct 31, 2007 7:02 am

Hi Alex,
For your information, I am using free version of Ranorex 1.2
Regards,
Prashant Barhate

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Wed Oct 31, 2007 11:38 am

With the free version just use the FindFormClassName instead of the FindForm method passing the value "MsoCommandBarPopup".

I just checked with the Ranorex 1.2 version, it's working for me if I use the code above (with FindForm exchanged by FindFormClassName).

If you're still having trouble, please send me your script or order the Pro Version Evaluation package.

Alex
Ranorex Support Team

prashantb
Posts: 9
Joined: Thu Aug 23, 2007 3:59 pm

Post by prashantb » Thu Nov 01, 2007 7:19 am

Hi Alex,
I am still having the trouble. Please refer my script.

using System;
using System.Collections.Generic;
using System.Text;
using Ranorex;

namespace RanoRexMenuActions
{
class Program
{
[STAThread]
static int Main(string[] args)
{
Console.WriteLine("Start Ranorex Menu Action Class");
Application.SleepTime = 50;
Mouse.MoveTime = 100;
Form form = Application.FindFormTitle("WindowsApplication1 - Microsoft Visual Studio", SearchMatchMode.MatchSubstring, true, 5000);
if (form == null)
{
Console.WriteLine("Visual Studio Window not found.");
return 1;
}
Console.WriteLine("Visual Studio 2005 Window Found.");
form.Activate();

Control solutionExplorer = form.FindChildText("Solution Explorer", SearchMatchMode.MatchExact);
solutionExplorer.Focus();

Element solutionElement = solutionExplorer.Element.FindChild(Role.OutlineItem);
Mouse.ClickElement(solutionElement, MouseButtonType.RightButton);

Application.Sleep(200);

Form contextMenuWindow = Application.FindFormClassName("MSOCommandBarPopup", 7);
//find menu items.
Element Properties = contextMenuWindow.Element.FindChild(Role.MenuItem, "Properties");

if (Properties == null)
{
Console.WriteLine("Cannot find AccuRevMenu");
return 1;
}

Mouse.ClickElement(Properties);

return 0;

}
}
}
Regards,
Prashant Barhate

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Fri Nov 02, 2007 10:33 am

If I change following line

Code: Select all

Form contextMenuWindow = Application.FindFormClassName("MSOCommandBarPopup", 7); 
to

Code: Select all

Form contextMenuWindow = Application.FindFormClassName("MsoCommandBarPopup");
the script works for me.

Alex
Ranorex Support Team