Unable to select submenu items : Automation API

Unable to select submenu items

Class library usage, coding and language questions.

Unable to select submenu items

Postby ChrisC » Tue Oct 02, 2007 4:51 pm

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(8)=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
ChrisC
 
Posts: 7
Joined: Tue Oct 02, 2007 4:36 pm

Postby Support Team » Tue Oct 02, 2007 5:29 pm

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: Select all
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: Select all
Application.PopupMenuSelectItem("New");


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

Postby ChrisC » Tue Oct 02, 2007 6:25 pm

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/clas ... s.Bar.html

The top level items (File, Edit, etc) are of the following Syncfusion class:
http://www2.syncfusion.com/library/clas ... rItem.html

Finally, the submenu items (New, Open, etc) are the following class:
http://www2.syncfusion.com/library/clas ... rItem.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
ChrisC
 
Posts: 7
Joined: Tue Oct 02, 2007 4:36 pm

Postby Support Team » Tue Oct 02, 2007 7:53 pm

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/downlo ... -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
User avatar
Support Team
Site Admin
Site Admin
 
Posts: 11576
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Postby ChrisC » Wed Oct 03, 2007 12:19 am

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: Select all
                //-----------------------------------------------------------------
                // 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
ChrisC
 
Posts: 7
Joined: Tue Oct 02, 2007 4:36 pm

Postby Support Team » Wed Oct 03, 2007 2:18 pm

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
User avatar
Support Team
Site Admin
Site Admin
 
Posts: 11576
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Postby ChrisC » Wed Oct 03, 2007 4:17 pm

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
ChrisC
 
Posts: 7
Joined: Tue Oct 02, 2007 4:36 pm

Postby Support Team » Wed Oct 03, 2007 4:47 pm

I sent you an email, please attach the image to your reply.

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

Postby Support Team » Wed Oct 03, 2007 9:18 pm

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: Select all
Control control = form.FindControlName("BarControl_MainMenu");
Element file = control.Element.FindChild(Role.MenuPopUp, "File");
Mouse.ClickElement(file);
ContextMenu.SelectItemText("New");

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

Postby ChrisC » Thu Oct 04, 2007 4:22 pm

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
ChrisC
 
Posts: 7
Joined: Tue Oct 02, 2007 4:36 pm

Postby Support Team » Thu Oct 04, 2007 10:04 pm

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: Select all
Element item = control.Element.FindChild(Role.MenuItem, "Save");
item.DoDefaultAction();


2. Use the SendKeys function to send a shortcut:

Code: Select all
Application.SendKeys("^s");


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

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

Postby ChrisC » Fri Oct 05, 2007 3:20 pm

The solutions you provided solved our problem.

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

Chris
ChrisC
 
Posts: 7
Joined: Tue Oct 02, 2007 4:36 pm


Return to Automation API

Who is online

Users browsing this forum: No registered users and 0 guests