Ranorex

How to get control of ContextMenu and select item on them

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



Joined: 20 Jul 2007
Posts: 20
Location: India

PostPosted: Thu Aug 02, 2007 4:00 pm    Post subject: How to get control of ContextMenu and select item on them
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
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
admin
Site Admin


Joined: 05 Jul 2006
Posts: 351

PostPosted: Thu Aug 02, 2007 8:32 pm    Post subject:
If you use a standard context menu, you can select an item in the following way:

Code: click into code to enlarge
ContextMenu.SelectItemText("ContextMenuItem2");

or
Code: click into code to enlarge
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
Back to top
View user's profile Send private message Visit poster's website
saurabh



Joined: 20 Jul 2007
Posts: 20
Location: India

PostPosted: Fri Aug 03, 2007 9:52 am    Post subject: Unable to get Popup Context Menu
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
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
admin
Site Admin


Joined: 05 Jul 2006
Posts: 351

PostPosted: Fri Aug 03, 2007 5:06 pm    Post subject:
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: click into code to enlarge
// 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: click into code to enlarge
// 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
Back to top
View user's profile Send private message Visit poster's website
saurabh



Joined: 20 Jul 2007
Posts: 20
Location: India

PostPosted: Wed Aug 22, 2007 10:31 am    Post subject: How can I Click in a Row of Listview thru Context Menu
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
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
admin
Site Admin


Joined: 05 Jul 2006
Posts: 351

PostPosted: Wed Aug 22, 2007 11:45 pm    Post subject:
You can use the Mouse.ClickElement function if you want to popup a context menu of a ListView item:

Code: click into code to enlarge
Mouse.ClickElement(row1, MouseButtonType.RightButton);


Jenö
Ranorex 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 -> RanorexNet 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