I am using TestStack White for UI automation of a Windows WPF chat application. I can get the Add button searching by AutomationID which pops a ContextMenu with two MenuItems to select to add contact or to create a group.
When I try to get the Create group MenuItem using its automationID, it throws an exception:
TestStack.White.AutomationException: Failed to get AutomationId = mitem_createGroup
These are the methods I've tried to get the MenuItem but failed:
mainWindow.Get(SearchCriteria.ByAutomationId("mitem_createGroup")).Click();
mainWindow.MenuBar.MenuItemBy(SearchCriteria.ByAutomationId("mitem_createGroup")).Click();
mainWindow.Get<MenuBar>(SearchCriteria.ByClassName("ContextMenu"));
var createGrpBtn = mainWindow.Get(SearchCriteria.ByText("Create group"));
mainWindow.PopupMenu("Create group");
I am out of ideas and need help figuring this out.
Edit: Here is the XAML for the contextmenu and menuitems. The ContextMenu is actually that of an ImageButton
<ContextMenu StaysOpen="False" FontSize="14" Style="{DynamicResource ContextMenuStyle}">
<MenuItem Height="32" Header="{lex:Loc STRING_MAIN_WINDOW_ADD_CONTACT}" Name="mitem_addContact" Click="mitem_addContact_Click">
<MenuItem.Icon>
<Image Source="{svg:SvgImage /ChatApp;component/Images/add_contact.svg}" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Height="32" Header="{lex:Loc STRING_MAIN_WINDOW_CREATE_GROUP}" Name="mitem_createGroup" Click="mitem_createGroup_Click">
<MenuItem.Icon>
<Image Source="{svg:SvgImage /ChatApp;component/Images/add_group.svg}" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>