AutomationElement.RootElement在iis中时为空

本文关键字:iis RootElement AutomationElement | 更新日期: 2023-09-27 18:27:02

下面是我的代码

AutomationElementCollection panes = AutomationElement.RootElement.FindAll(TreeScope.Children, paneCondition);

基本上,上面的代码拉取了我桌面上所有打开的窗口。当在VisualStudioIDE中使用Debug在本地运行时,它可以正常工作,但当部署到IIS时会出现问题。

AutomationElementCollection在IIS中时为空,而在集合中的项数不为0的Visual Studio中运行时则为空。

现在我该如何解决这个问题?如有任何帮助,我们将不胜感激:)

顺便说一句,我想做的是自动登录Windows安全提示。

AutomationElement.RootElement在iis中时为空

我要冒险说simmon mourier是正确的,但假设他们是一种方法,我会尝试这样的方法来确认窗口根本无法返回。

这将返回你传递到它的所有子自动化元素。

    /// <summary>
    /// Returns all children elements of an automation element.
    /// </summary>
    public virtual List<AutomationElement> GetAllAutomationElements(AutomationElement aeElement)
    {
        AutomationElement aeFirstChild = TreeWalker.RawViewWalker.GetFirstChild(aeElement);
        List<AutomationElement> aeList = new List<AutomationElement>();
        aeList.Add(aeFirstChild);
        AutomationElement aeSibling = null;
        int count = 0;
        while ((aeSibling = TreeWalker.RawViewWalker.GetNextSibling(aeList[count])) != null)
        {
            aeList.Add(aeSibling);
            count++;
        }
        return aeList;
    }

然后将列表吐到一个文件或其他文件中,这样您就可以在登录后确认运行时实际可用的内容。