Ranorex

Activate menu item without sendkey or mouse movement

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



Joined: 11 Jul 2007
Posts: 1

PostPosted: Wed Jul 11, 2007 11:31 pm    Post subject: Activate menu item without sendkey or mouse movement
.Net 2005, C#, v1.2

I am trying to get a handle on a menu item element I want, and then tell it to DoDefaultAction()

By doing ...Element.GetChild(2).GetChild(1).DoDefaultAction I can open the menu -- this works fine.

Before I open the menu, I can find the subitem I want to select by doing ...Element.GetChild(2).GetChild(1).GetChild(0).GetChild(12) -- but I cannot DoDefaultAction (I assume because menu is not open, this element's state is Unavailable)

After the menu is open, though, the last child element has only one child, not the 19 that it should! If I look inside that child, it has no children at all... where did my menu items go?

If I'm going about this entirely the wrong way, let me know... I need it to be without sendkeys or mouse movement, but activate the menu item.

Thanks!
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 05 Jul 2006
Posts: 351

PostPosted: Thu Jul 12, 2007 9:37 pm    Post subject:
Quote:
I need it to be without sendkeys or mouse movement, but activate the menu item.


Please try the following:
(This code works with the VS2005Application sample)

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

Element menuItem = menuStrip.Element.FindChild(Role.MenuItem, "Submenu2");
if (menuItem == null)
    return 1;
menuItem.DoDefaultAction();
Application.Sleep(500);

menuItem = menuItem.FindChild(Role.MenuItem, "Submenu2Item3");
if (menuItem == null)
    return 1;
menuItem.DoDefaultAction();
Application.Sleep(500);

menuItem = menuItem.FindChild(Role.MenuItem, "Subitem13");
if (menuItem == null)
    return 1;
menuItem.DoDefaultAction();
Application.Sleep(500);

menuItem = menuItem.FindChild(Role.MenuItem, "Subitem31");
if (menuItem == null)
    return 1;
menuItem.DoDefaultAction();


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