I am trying to make an automated test using C#/NUnit/WinAppDriver where I open the Task Scheduler and find a specific folder in the Task Scheduler Library. When I run the test, Task Scheduler opens, but then I get the following Exception:
OpenQA.Selenium.WebDriverException : Failed to locate opened application window with appId: C:\WINDOWS\System32\taskschd.msc, and processId: 3796
(NOTE: the processId seems to be random every time)
Here is the code that I am using to try this test:
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using System;
namespace AutomationProject
{
[TestFixture]
public class ScenarioTaskSchedular
{
public static WindowsDriver<WindowsElement> DesktopSession;
private const string TaskSchedularId = @"C:\\WINDOWS\\System32\\taskschd.msc";
[Test]
public void FindWFolder()
{
var TaskSchedularLibrary = DesktopSession.FindElementByName("Task Scheduler Library");
var TreeItems = TaskSchedularLibrary.FindElementsByXPath("//[@LocalizedControlType=\"tree item\"]");
foreach (var element in TreeItems)
{
Console.WriteLine(element.GetAttribute("Value.Value")); //To check each folder in the task schedular library
}
}
[SetUp]
public static void SetUp()
{
AppiumOptions options = new AppiumOptions();
options.AddAdditionalCapability("app", TaskSchedularId);
options.AddAdditionalCapability("deviceName", "WindowsPC");
DesktopSession = new WindowsDriver<WindowsElement>(new Uri(DriverUrl), options);
Assert.IsNotNull(DesktopSession);
}
[TearDown]
public static void TearDown()
{
DesktopSession.Quit();
}
}
}
I'm not really sure why this is happening, and I could not find a solution anywhere for this issue. Any help would be greatly appreciated.