Ranorex

Unable to select submenu items

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



Joined: 02 Oct 2007
Posts: 7

PostPosted: Tue Oct 02, 2007 5:51 pm    Post subject: Unable to select submenu items
We are currently evaluating Ranorex using the free trial version. I am trying to select submenu items (e.g. File->New), and have not been successful. I can successfully dump the menu tree as shown below:

Submenu(1)=File
Item(1)=New
Item(2)=Open...
Item(3)=Close
Item(4)=Save
Item(5)=Save As...
Item(6)=Page Setup...
Item(7)=Print Preview
Item(Cool=Print...
Item(9)=Recent Files
Item(10)=Exit
Submenu(2)=Edit
Item(1)=Undo Move Nodes
Item(2)=Redo
Item(3)=Select All
Item(4)=Cut
Item(5)=Copy
Item(6)=Paste
Item(7)=Delete
etc.

However, the following C# code does not work: mainMenu.SelectItemText("File", "New");
mainMenu.SelectPosition(1, 1);

The File menu item is selected, but not the submenu item.

We are using VS2005 with .Net 2.0. We are also using third party controls from Syncfusion.

Any help would be greatly appreciated.

Thanks,
Chris
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 435

PostPosted: Tue Oct 02, 2007 6:29 pm    Post subject:
Quote:
We are also using third party controls from Syncfusion.
The File menu item is selected, but not the submenu item.


Does the submenu item have a shortcut?
Is the menu bar in a control? (Please check it with RanorexSpy)

Please try the following:

Suggestion1:

Element class:

Code: click into code to enlarge
Control menuStrip = form.FindControlName("menuStrip1");

Element menuItem = menuStrip.Element.FindChild(Role.MenuItem, "New");
if (menuItem == null)
    return 1;
Mouse.ClickElement(menuItem);


Suggestion 2:

Try with the PopupMenuSelectItem function:

Code: click into code to enlarge
Application.PopupMenuSelectItem("New");


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



Joined: 02 Oct 2007
Posts: 7

PostPosted: Tue Oct 02, 2007 7:25 pm    Post subject:
Thanks for your quick reply.

Our submenu item does have a shortcut (Ctrl+N).

The menu bar is not derived from a Windows Control. The mainMenu is the following Syncfusion class:
http://www2.syncfusion.com/library/classref/Syncfusion.Windows.Forms.T ools.XPMenus.Bar.html

The top level items (File, Edit, etc) are of the following Syncfusion class:
http://www2.syncfusion.com/library/classref/Syncfusion.Windows.Forms.T ools.XPMenus.ParentBarItem.html

Finally, the submenu items (New, Open, etc) are the following class:
http://www2.syncfusion.com/library/classref/Syncfusion.Windows.Forms.T ools.XPMenus.BarItem.html

I tried the following code per your first suggestion and it did not work.
Control menuStrip = mainForm.FindControlName("BarControl_MainMenu");
Element menuItem = menuStrip.Element.FindChild(Role.MenuItem, "New");
if (menuItem == null)
return;
Mouse.ClickElement(menuItem);

menuItem was not null, but the ClickElement did not do anything.

I am unable to try your second suggestion because I am using the trial version. According to the documentation, PopupMenuSelectItem is only supported in RanorexPro.

I would greatly appreciate any other help you can provide.

Thanks,
Chris
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 435

PostPosted: Tue Oct 02, 2007 8:53 pm    Post subject:
Can you please try this issue with the Recorder.
Start recording, click "File", "New", then stop recording and try to replay it.
You can download the recorder from:

http://www.ranorex.com/fileadmin/downloads/RanorexRecorder-1.2.1-Beta1 .zip

What is the "Element Name" of the New submenu?
Please check it with RanorexSpy (you must enable the HotTracker).

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



Joined: 02 Oct 2007
Posts: 7

PostPosted: Wed Oct 03, 2007 1:19 am    Post subject:
I recorded the click "File", "New" and replayed it. The mouse arrow clicked the "File" menu item. After that, the mouse arrow moved to the top-left corner of the screen (not my application).

Here is the C# code generated by the recording:

Code: click into code to enlarge

                //-----------------------------------------------------------------
                // Find form by title and class name
                //-----------------------------------------------------------------
                form = Application.FindForm("PurePath Studio Graphical Development Environment (Edit Mode)", SearchMatchMode.MatchExact, "WindowsForms10.Window.8.app.0.33c0d9d", false, 5000);
                form.Activate();

                // Find child by control name
                parent = form.FindControlName("ToolbarHost_MainMenu");

                // Find child by control name
                control = parent.FindControlName("BarControl_MainMenu");
                control.Focus();
                controlElement = control.Element;

                // Find child element by Role=MenuPopUp Name=File ClassName=WindowsForms10.Window.8.app.0.33c0d9d
                element = controlElement.FindChild(Role.MenuPopUp, "File", "WindowsForms10.Window.8.app.0.33c0d9d");
                Mouse.ClickElement(element, MouseButtonType.LeftButton, new Point(22, 0), 1, 100);

                //-----------------------------------------------------------------
                // Find form by title and class name
                //-----------------------------------------------------------------
                form = Application.FindForm("", SearchMatchMode.MatchExact, "WindowsForms10.Window.808.app.0.33c0d9d", false, 5000);
                form.Activate();

                // Find child by class name
                control = form.FindClassName("WindowsForms10.Window.8.app.0.33c0d9d", 1);
                control.Focus();
                Mouse.ClickControl(control, MouseButtonType.LeftButton, new Point(21, 6), 1, 1973);


I also used checked the Element Name of the New Submenu. The name of the element is "New".

Thanks in advance for your help.

Chris
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 435

PostPosted: Wed Oct 03, 2007 3:18 pm    Post subject:
The Submenu seems to be a special Popup menu of Syncfusion.

Can you send me the screen shot of RanorexSpy if the mouse pointer is over the New submenu item (HotTracker should be enabled).
It's possible, that the Submenu is a top-level window and you have to find it with the Application.FormFind() function.

(Or can you send me a small sample application with such a menu?)

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



Joined: 02 Oct 2007
Posts: 7

PostPosted: Wed Oct 03, 2007 5:17 pm    Post subject:
I have the screen shot of RanorexSpy. Is there a way to upload an image to this forum?

Thanks in advance for your help.

Chris
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 435

PostPosted: Wed Oct 03, 2007 5:47 pm    Post subject:
I sent you an email, please attach the image to your reply.

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


Joined: 07 Jul 2006
Posts: 435

PostPosted: Wed Oct 03, 2007 10:18 pm    Post subject:
It seems to be a problem with the position of the menu item.
The submenu is like a context menu, so you can use the ContextMenu.SelectItemText() function.

Please try the following:

Code: click into code to enlarge
Control control = form.FindControlName("BarControl_MainMenu");
Element file = control.Element.FindChild(Role.MenuPopUp, "File");
Mouse.ClickElement(file);
ContextMenu.SelectItemText("New");

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



Joined: 02 Oct 2007
Posts: 7

PostPosted: Thu Oct 04, 2007 5:22 pm    Post subject:
I tried your suggestion and the result was a little better, but still not right.

I used the code you included in your previous post. The "File" menu item is clicked, but then the "Close" submenu item is clicked. That is the third item in the submenu, and "New" is the first item. I removed the shortcut and accelerator keys from the "New" submenu item, but it did not help.

I would greatly appreciate any more help you can provide.

Chris
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 435

PostPosted: Thu Oct 04, 2007 11:04 pm    Post subject:
I think i found the real problem.
It seems to be a bug in the Syncfusion Menu class, all submenu items return the same element location, so you cannot use this property.

You have only two possibilities.

1. Use the DoDefaultAction to select the menu item:

Code: click into code to enlarge
Element item = control.Element.FindChild(Role.MenuItem, "Save");
item.DoDefaultAction();


2. Use the SendKeys function to send a shortcut:

Code: click into code to enlarge
Application.SendKeys("^s");


I tried both possibilities with the XPMenus_MDI sample and they worked for me.

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



Joined: 02 Oct 2007
Posts: 7

PostPosted: Fri Oct 05, 2007 4:20 pm    Post subject:
The solutions you provided solved our problem.

I can't thank you enough for your great support!

Chris
Back to top
View user's profile Send private message
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