我正在使用UI自动化进行GUI测试.
我的窗口标题包含由文件名追加的应用程序名称.
所以,我想在我的Name PropertyCondition中指定Contains.
我检查了重载,但它与Ignoring Name of Case值有关.
任何人都可以让我知道如何在我的名称PropertyCondition中指定包含?
问候,
kvk938
最佳答案 据我所知,他们在使用name属性时无法进行包含,但你可以做类似的事情.
/// <summary>
/// Returns the first automation element that is a child of the element you passed in and contains the string you passed in.
/// </summary>
public AutomationElement GetElementByName(AutomationElement aeElement, string sSearchTerm)
{
AutomationElement aeFirstChild = TreeWalker.RawViewWalker.GetFirstChild(aeElement);
AutomationElement aeSibling = null;
while ((aeSibling = TreeWalker.RawViewWalker.GetNextSibling(aeFirstChild)) != null)
{
if (aeSibling.Current.Name.Contains(sSearchTerm))
{
return aeSibling;
}
}
return aeSibling;
}
然后,您将执行此操作以获取桌面并将带有字符串的桌面传递到上述方法中
/// <summary>
/// Finds the automation element for the desktop.
/// </summary>
/// <returns>Returns the automation element for the desktop.</returns>
public AutomationElement GetDesktop()
{
AutomationElement aeDesktop = AutomationElement.RootElement;
return aeDesktop;
}
完整的用法看起来像
AutomationElement oAutomationElement = GetElementByName(GetDesktop(), "Part of my apps name");