问题
I am creating a software process automation using the language C # framework by White \ TestStack.
I have a problem because I am unable to capture an option when I click with the right mouse button.
Image Preview
The code I'm using to try this
panel.RightClick();
var propClick = _mainWindow.Get<White.Core.UIItems.MenuItems.PopupMenu>(SearchCriteria.ByText("Propeties"));
propClick .Click();
can not capture the option, making the variable becomes null propClick
Sorry my english sucks :(
Help!
Thanks :)
回答1:
Apparently you can’t get context menu via Get<T>
method. I’ve been digging around that approach until I’ve found this piece of documentation:
https://github.com/TestStack/White/blob/6c61106f2a62686636eb7cace0ee187a02db7295/docs/UIItems.md#menu-bars
So in your case it should be:
panel.RightClick();
var popup = _mainWindow.Popup;
var properties_item = popup.ItemBy(
SearchCriteria.ByText( "Propeties" )
);
properties_item.Click();
I’d also suggest using automation ID for every control you wish to automate.
回答2:
I haven't tried anything with right mouse menus. Does the menu show after your
panel.RightClick();
Else, isn't the context menu part of your panel?
Have you tried using
panel.RightClick();
var propClick = panel.Get<MenuItems.PopupMenu>(SearchCriteria.ByText("Propeties"));
propClick.Click();
instead?
Or maybe you could try Menu instead of PopupMenu
var propClick = panel.Get<MenuItems.Menu>(SearchCriteria.ByText("Propeties"));
or just let white decide for you first, and read the type by putting a breakpoint
var propClick = panel.Get(SearchCriteria.ByText("Propeties"));
EDIT: To add to this, the following methods might help to select the context menu by using the keyboard commands.
To add to that, you might want to try to select the menu with keyboard. White does not have a special key for the context menu (right mouse menu), but the method below can help with that.
/// <summary>
/// Right mouse click simulation (SHIFT+F10)
/// </summary>
/// <param name="container">Container in whish the click should occur.</param>
private static void ShowContextMenu(this UIItemContainer container)
{
container.Keyboard.HoldKey(KeyboardInput.SpecialKeys.SHIFT);
container.Keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.F10);
container.Keyboard.LeaveKey(KeyboardInput.SpecialKeys.SHIFT);
}
and this one to select the context menu
/// <summary>
/// Get the context menu (right mouse menu) of <paramref name="container"/> whre the current focus is.
/// </summary>
/// <param name="mainWindow">Main window of the application, because the context menu is always a child of the window.</param>
/// <param name="container">Container on which the right click shoul occur.</param>
/// <returns>Context menu</returns>
internal static PopUpMenu GetContextMenuOf(this Window mainWindow, UIItemContainer container)
{
using (CoreAppXmlConfiguration.Instance.ApplyTemporarySetting(c => c.PopupTimeout = 750))
{
container.ShowContextMenu();
return mainWindow.Popup;
}
}
回答3:
panel.RightClick();
Thread.Sleep(500);
var windows = application.GetWindows();
foreach (Window window in windows) {
if (window.Name == "") {
var propClick = window.Get<PopupMenu>(SearchCriteria.ByText("Propeties"));
propClick.Click();
}
}
From what I've seen context menus are separate Window with no name, but this is application specific ofcourse
来源:https://stackoverflow.com/questions/26713272/find-option-to-right-click-c-sharp-white-teststack-ui-automation