Ranorex

PopUp menu not recognized

 
Post new topic   Reply to topic    Ranorex Forum Index -> RanorexPython
View previous topic :: View next topic  
Author Message
prashantb



Joined: 23 Aug 2007
Posts: 9

PostPosted: Thu Oct 25, 2007 11:45 am    Post subject: PopUp menu not recognized
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
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 344

PostPosted: Thu Oct 25, 2007 10:47 pm    Post subject:
Quote:
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: click into code to enlarge
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
Back to top
View user's profile Send private message Visit poster's website
prashantb



Joined: 23 Aug 2007
Posts: 9

PostPosted: Mon Oct 29, 2007 10:28 am    Post subject:
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
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 344

PostPosted: Mon Oct 29, 2007 7:26 pm    Post subject:
Can you please post us the source code of your test application.
We will check it with visual studio.

Jenö
Ranorex Team
Back to top
View user's profile Send private message Visit poster's website
prashantb



Joined: 23 Aug 2007
Posts: 9

PostPosted: Tue Oct 30, 2007 1:40 pm    Post subject:
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
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 344

PostPosted: Tue Oct 30, 2007 3:23 pm    Post subject:
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: click into code to enlarge
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
Back to top
View user's profile Send private message Visit poster's website
prashantb



Joined: 23 Aug 2007
Posts: 9

PostPosted: Wed Oct 31, 2007 8:01 am    Post subject:
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
Back to top
View user's profile Send private message
prashantb



Joined: 23 Aug 2007
Posts: 9

PostPosted: Wed Oct 31, 2007 8:02 am    Post subject:
Hi Alex,
For your information, I am using free version of Ranorex 1.2
_________________
Regards,
Prashant Barhate
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 344

PostPosted: Wed Oct 31, 2007 12:38 pm    Post subject:
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
Back to top
View user's profile Send private message Visit poster's website
prashantb



Joined: 23 Aug 2007
Posts: 9

PostPosted: Thu Nov 01, 2007 8:19 am    Post subject:
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
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 344

PostPosted: Fri Nov 02, 2007 11:33 am    Post subject:
If I change following line
Code: click into code to enlarge
Form contextMenuWindow = Application.FindFormClassName("MSOCommandBarPopup", 7);

to
Code: click into code to enlarge
Form contextMenuWindow = Application.FindFormClassName("MsoCommandBarPopup");

the script works for me.

Alex
Ranorex Support Team
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Ranorex Forum Index -> RanorexPython All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum