How to get control of ContextMenu and select item on them

Class library usage, coding and language questions.
saurabh
Posts: 20
Joined: Fri Jul 20, 2007 1:11 pm
Location: India
Contact:

How to get control of ContextMenu and select item on them

Post by saurabh » Thu Aug 02, 2007 3:00 pm

In my application there on the mouse right click i am getting context menu but i am unable to find control of ContextMenu from Ranorex Spy.So please guide me to get control of ContextMenu and how to select an element from there.if you can give me code sample for the same it will be great.
Thanks in advance
Regards,
Saurabh Shrivastava
GE Global Research
Bangalore India

webops
Site Admin
Site Admin
Posts: 349
Joined: Wed Jul 05, 2006 7:44 pm

Post by webops » Thu Aug 02, 2007 7:32 pm

If you use a standard context menu, you can select an item in the following way:

Code: Select all

ContextMenu.SelectItemText("ContextMenuItem2");
or

Code: Select all

Application.PopupMenuSelectItem("ContextMenuItem2");
Please also see the sample RanorexProVS2005Sample3.

If you use a 3rd party context menu control, then you should search first the context menu on the top-level with Application.FindForm() and then the items with Element.FindChild().

Jenö
Ranorex Team

saurabh
Posts: 20
Joined: Fri Jul 20, 2007 1:11 pm
Location: India
Contact:

Unable to get Popup Context Menu

Post by saurabh » Fri Aug 03, 2007 8:52 am

Actually my problem is different. In my application Context Menu is appeared only after right click mouse in current form it’s not the permanent child of current form so I am doing right mouse click by this code.I am working in VS2003 using RanorexNet.dll.

form = Application::FindFormTitle("Alarm manager",Ranorex::SearchMatchMode::MatchExact,true,5000);
Mouse::MoveToControl(form);
Mouse::ButtonDown(MouseButtonType::RightButton);
Mouse::ButtonUp(MouseButtonType::RightButton);

Now my context menu has appeared and there is no control showing by Ranorex Spy. Only Element role and name is there.

To understand my problem better like if you want to automate the following step to get display property window of your desktop through Ranorex.
1.Mouse right click on your desktop window
2.Now Popup Context Menu will appear
3.Now go to the properties item in Popup Context Menu
4.Click on properties item
5.now Display Properties window has opened.
If you will simultaneously observe the control and element value for each step through Ranorex spy. You will find when you would do right click ,Popup Context Menu will appear with Element Role: window and Name:context.
Now go to the properties Item it will appear with Element Role:MenuItem and Name:Properties.
Now I want to click on properties so it should open Display Properties Window for your Desktop.I have written following in the continuation of above code but it is not working:

Element *context = form->Element->FindChild(Ranorex::Role::Window, "Context");
Element *MenuItem1 = form->Element->FindChild(Ranorex::Role::MenuItem , "Hide Controls");
Mouse::MoveToElement(MenuItem1 );
Mouse::ClickElement(MenuItem1 );

Note:Here “Hide Controls” is one of the Menu item of Popup Context Menu in my application here you can replace this with Menu Item “Properties “

Please provide me correct code ASAP. Its argent.
Thanks in Advance!
Regards,
Saurabh Shrivastava
GE Global Research
Bangalore India

webops
Site Admin
Site Admin
Posts: 349
Joined: Wed Jul 05, 2006 7:44 pm

Post by webops » Fri Aug 03, 2007 4:06 pm

A context menu is a top-level window and not a child of a Form or Windows application.
You can popup a context menu and select an item as follows:

Code: Select all

// Click right mouse button
Mouse.ClickElement(element, MouseButtonType.RightButton);
// Wait 200msec
Application.Sleep(200);
// Select the context menu item with the name "Properties"
Application.PopupMenuSelectItem("Properties", 200);
or

Code: Select all

// Click right mouse button
Mouse.ClickElement(element, MouseButtonType.RightButton);
// Wait 200msec
Application.Sleep(200);
// Select the context menu item with the name "Properties"
ContextMenu.SelectItemText("Properties");
A standard context menu has a class name: #32768, if you get the same, then the sample above will work.
If you get an other class name in RanorexSpy, then you should search the context menu with the Application.FindForm function.

Jenö
Ranorex Team

saurabh
Posts: 20
Joined: Fri Jul 20, 2007 1:11 pm
Location: India
Contact:

How can I Click in a Row of Listview thru Context Menu

Post by saurabh » Wed Aug 22, 2007 9:31 am

I want to perform contecx menu operation for a selected rows in ListView.Like if I have 10 rows in List View then I want select 3rd and 5th row and get popup menu for the same means I want to first focus on selected row in ListView then want to get Contex Menu for that paricular row.How can i do that?Currentaly When i am trying to do that i am getting the Contex Menu for a fix rows which is 5th or sometime 6th row.If i want to get the Context menu for first or second row i am unable to do that.
I am using RanorexPro1.2.Here is my code

Form* form = Application::FindFormTitle("Alarm manager",Ranorex::SearchMatchMode::MatchExact,true,5000);
ListView* lvCtrl = form->FindListView(DispCompVal);
Mouse::MoveToControl(lvCtrl);
lvCtrl->Focus();
String* RowText;
RowText = lvCtrl->GetItemText(1,0);
Element *row1 =lvCtrl->Element->FindChild(Ranorex::Role::ListItem,RowText);
row1->Select(Selection::TakeSelection);

what will be the code after this to get contex menu for 1st row
Regards,
Saurabh Shrivastava
GE Global Research
Bangalore India

webops
Site Admin
Site Admin
Posts: 349
Joined: Wed Jul 05, 2006 7:44 pm

Post by webops » Wed Aug 22, 2007 10:45 pm

You can use the Mouse.ClickElement function if you want to popup a context menu of a ListView item:

Code: Select all

Mouse.ClickElement(row1, MouseButtonType.RightButton);
Jenö
Ranorex Team