I have an application that is set to run at a specific time of day when the user is logged off. It uses a combination of Selenium and UI Automation in C# to download a file every day. When run logged in, everything is fine. However, when I run the application via the task scheduler it fails when it attempts to find an AutomationElement.
I start off with the following PropertyConditions:
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);
Originally, I attempted to find the "Desktop" root element by
AutomationElement aeDesktop =AutomationElement.RootElement;
However, my research led me to believe that no desktop is actually created when an application is ran this way. I also double checked that NoInteractiveServices is set to false in the registry, then took screenshots via Selenium to make sure the web automation was working correctly - It was.
I double checked the RootElement writing all the RootElement's TreeScope.Children to a log file via the following code
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++;
}
And nothing showed up.
I then tried to find an AutomationElement from a process handle.
var process = Process.GetProcessesByName("firefox").First();
AutomationElement aeDesktop = AutomationElement.FromHandle(process.Handle);
And again, nothing.
I am stuck trying to find some sort of AutomationElement to "hook on to" so then I can start searching for that Save Dialog Box. Would love to know what you all think, any suggestions, tips, or "HEY BUDDY - YOU ARE DOING IT WRONG!" Thanks all in advance!
So not a complete answer, but one that address my specific situation, not the general one I asked above.