C# 当使用任务计划程序且用户已注销时,如何查找AutomationElement?

C# 当使用任务计划程序且用户已注销时,如何查找AutomationElement?,c#,selenium,automation,ui-automation,automationelement,C#,Selenium,Automation,Ui Automation,Automationelement,我有一个应用程序,设置为在用户注销时在一天中的特定时间运行。它将Selenium和C#中的UI自动化结合起来,每天下载一个文件。当run登录时,一切正常。但是,当我通过任务调度器运行应用程序时,当它尝试查找AutomationElement时,它会失败 我从以下属性条件开始: PropertyCondition browserProp=new PropertyCondition(AutomationElement.NameProperty,"Website 1- Mozilla Firefox

我有一个应用程序,设置为在用户注销时在一天中的特定时间运行。它将Selenium和C#中的UI自动化结合起来,每天下载一个文件。当run登录时,一切正常。但是,当我通过任务调度器运行应用程序时,当它尝试查找AutomationElement时,它会失败

我从以下属性条件开始:

 PropertyCondition browserProp=new PropertyCondition(AutomationElement.NameProperty,"Website 1- Mozilla Firefox",PropertyConditionFlags.IgnoreCase);
 PropertyCondition saveDiagProp= new PropertyCondition(AutomationElement.NameProperty,"Opening File.xls",PropertyConditionFlags.IgnoreCase);
 PropertyCondition saveRadioBut = new PropertyCondition(AutomationElement.NameProperty, "Save File", PropertyConditionFlags.IgnoreCase);
 PropertyCondition okBut= new PropertyCondition(AutomationElement.NameProperty, "OK", PropertyConditionFlags.IgnoreCase);
最初,我试图通过

 AutomationElement aeDesktop =AutomationElement.RootElement;
然而,我的研究使我相信,当应用程序以这种方式运行时,实际上不会创建任何桌面。我还仔细检查了NoInteractiveServices在注册表中是否设置为false,然后通过Selenium拍摄了屏幕截图,以确保web自动化工作正常——确实如此

我仔细检查了RootElement,通过以下代码将所有RootElement的TreeScope.Children写入日志文件

AutomationElementCollection desktopChildren =   aeDesktop.FindAll(    TreeScope.Children, Condition.TrueCondition); 
foreach(AutomationElement ae in desktopChildren)
        {
            System.IO.File.AppendAllText(downloadLocation + "errorlog.txt", "RootChild [" +x+"] "+ ae.Current.Name + Environment.NewLine);
            x++;
        }
什么也没有出现

然后我试图从进程句柄中找到AutomationElement

var process = Process.GetProcessesByName("firefox").First();
AutomationElement aeDesktop = AutomationElement.FromHandle(process.Handle);
再说一次,什么也没有


我一直在试图找到某种自动元素来“钩住”,这样我就可以开始搜索“保存”对话框了。我很想知道你们的想法,任何建议,提示,或者“嘿,伙计,你们做错了!”提前谢谢大家

所以这不是一个完整的答案,而是一个针对我具体情况的答案,而不是我上面问的一般性答案