unable to click on MenuItem

Aug 30, 2010 at 4:35 PM
Edited Aug 30, 2010 at 5:48 PM

Hello, I am new with Whte tool and having difficulty in clicking on a menu item. I first click on a buuton which brings menu items and when trying to click on a  menu item, New it works however when trying to click on submenu item "Group" (this is a submenu item of the New) Visual studio displays and unhandled exception error. can someone please help. Thanks in advance.

Button

 

 brandIconButton = Window.Get<Button>(SearchCriteria.ByAutomationId("_brandIconButton"

));

 

 

Assert.IsNotNull(brandIconButton);

brandIconButton.Click();

 

Thread.Sleep(500);

 

Tried the following

Menu addNewGroup = Window.Get<Menu>(SearchCriteria.ByText("Group"));

addNewGroup.Click();

 or

 

Menu addNewGroup = Window.Get<Menu>(SearchCriteria.ByAutomationId("addNewGroup"));

addNewGroup.Click()

 

Aug 31, 2010 at 8:29 AM

WPF or WinForm?

ConetextMenu or Mainmenu?

 

Throndorin

 

 

 

 

 

Aug 31, 2010 at 2:35 PM

It's a WPF application and it's a Mainmenu. Any help will be appreciated. Thanks for your time.

Sep 1, 2010 at 7:16 AM

Hi

/// <summary>
/// Gets the menu.
/// </summary>
/// <param name="mainMenu">The main menu.</param>
/// <param name="subMenu">The sub menu.</param>
/// <returns></returns>
public static Menu GetMenu(MainMenus mainMenu, params MainSubMenu[] subMenu)
{
  Menu mainMenuItem = GetMenu( mainMenu );

  if (subMenu != null)
  {
	List<MainSubMenu> menus = new List<MainSubMenu>( subMenu );
	return GetSubMenuItem(mainMenuItem, menus);
  }

  return mainMenuItem;
  
}

/// <summary>
/// Gets the menu.
/// </summary>
/// <param name="mainMenu">The main menu.</param>
/// <param name="subMenu">The sub menu.</param>
/// <returns></returns>
public static Menu GetMenu(MainMenus mainMenu, params EEditContextMenuItems[] subMenu)
{

  Menu mainMenuItem = GetMenu( mainMenu );

  if (subMenu != null)
  {
	List<EEditContextMenuItems> menus = new List<EEditContextMenuItems>(subMenu);
	return GetSubMenuItem(mainMenuItem, menus);
  }

  return mainMenuItem;

}

/// <summary>
/// Gets the menu.
/// </summary>
/// <param name="mainMenu">The main menu.</param>
/// <returns></returns>
public static Menu GetMenu(MainMenus mainMenu)
{
  return (Menu)Window.Get(SearchCriteria.ByAutomationId(GetMainMenuAuID(mainMenu)));
}


/// <summary>
/// Gets the sub menu iem.
/// </summary>
/// <param name="menu">The menu.</param>
/// <param name="subMenu">The sub menu.</param>
/// <returns></returns>
private static Menu GetSubMenuItem(Menu menu, List<MainSubMenu> subMenu)
{
  menu.Click();
  Menu menuItem = menu.SubMenu( SearchCriteria.ByAutomationId( GetSubMenuAuID( subMenu[ 0 ] )));
  subMenu.Remove( subMenu[ 0 ] );

  if(subMenu.Count!=0)
  {
	menuItem.Click();
	return GetSubMenuItem( menuItem, subMenu );
  }

  return menuItem;
}

/// <summary>
/// Gets the sub menu iem.
/// </summary>
/// <param name="menu">The menu.</param>
/// <param name="subMenu">The sub menu.</param>
/// <returns></returns>
private static Menu GetSubMenuItem(Menu menu, List<EEditContextMenuItems> subMenu)
{
  menu.Click();
  Thread.Sleep( 500 );
  Menu menuItem = menu.SubMenu(SearchCriteria.ByAutomationId(EditContextMenuItems.GetAuID(subMenu[0])));
  subMenu.Remove(subMenu[0]);

  if (subMenu.Count != 0)
  {
	menuItem.Click();
	return GetSubMenuItem(menuItem, subMenu);
  }

  return menuItem;
}

MainMenus and EEditContextMenuItems are enums

EditContextMenuItems.GetAuID gets the correct automation ID to the menu, hope your menus has automation ID's if not you shoud change to get by text, but this is not language indepandent

Throndorin