[英]Find option to right click c# White/TestStack UI Automation
I am creating a software process automation using the language C # framework by White \\ TestStack. 我正在使用White \\ TestStack的C#框架语言创建软件过程自动化。
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 无法捕获选项,使变量变为null propClick
Sorry my english sucks :( 对不起我的英文糟透了:(
Help! 救命!
Thanks :) 谢谢 :)
Apparently you can't get context menu via Get<T>
method. 显然你不能通过
Get<T>
方法获得上下文菜单。 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 我一直在挖掘这种方法,直到我找到这篇文档: 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. 我还建议为您希望自动化的每个控件使用自动化ID。
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 或者也许您可以尝试使用Menu而不是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;
}
}
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 从我所看到的上下文菜单是单独的窗口没有名称,但这是应用程序特定的课程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.