如何在UI自动化PropertyCondition中指定包含

kvk*_*938 5 ui-automation

我正在使用UI Automation进行GUI测试。

我的窗口标题包含应用程序名称,并附加文件名。

因此,我想在我的名称PropertyCondition中指定包含。

我检查了重载,但它与忽略名称的大小写值有关。

谁能让我知道如何在我的名字PropertyCondition中指定包含?

问候,

kvk938

Max*_*ung 2

据我所知,在使用 name 属性时,他们无法执行 contains 操作,但您可以执行类似的操作。

    /// <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;
    }
Run Code Online (Sandbox Code Playgroud)

然后你可以这样做来获取桌面并将桌面和你的字符串传递到上面的方法中

    /// <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;
    }
Run Code Online (Sandbox Code Playgroud)

完整的用法看起来像

 AutomationElement oAutomationElement = GetElementByName(GetDesktop(), "Part of my apps name");
Run Code Online (Sandbox Code Playgroud)