Search code examples
c#appiumwinappdriver

WinAppDriver element not found


I'm trying to use WinAppDriver, Appium & C# to do some UI automation on an ancient Delphi 5 application. It fires up the app, there's a little splash screen then a windows modal box for logging in. The usernames already filled out, so just type out the password and press the OK button.

var appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", @"C:\APP\APP1998.exe");
appCapabilities.SetCapability("deviceName", "WindowsPC");
Session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
Assert.IsNotNull(Session);
Assert.IsNotNull(Session.SessionId);

Assert.AreEqual("APP1998", Session.Title.ToUpper());
Session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
Session.Keyboard.SendKeys("PASSWORD1");

These all fail:

//The logon dialog OK button
Session.FindElementByName("OK").Click();
//The File menu
Session.FindElementByName("File").Click();
//The Exit command from the File menu
Session.FindElementByName("Exit").Click();

I'm using WinAppDriver 1.0 and Appium 3.0.0.2 with Visual Studio, WinAppDriver and Inspect.exe running as admin.

Inspect shows the login screen and the splash screen as separate screens which are not connected in the tree.

The page source after you log in is:

  <?xml version="1.0" encoding="utf-16"?><Window AcceleratorKey="" AccessKey="" AutomationId="" ClassName="TApplication" FrameworkId="Win32" HasKeyboardFocus="False" HelpText="" IsContentElement="True" IsControlElement="True" IsEnabled="True" IsKeyboardFocusable="True" IsOffscreen="True" IsPassword="False" IsRequiredForForm="False" ItemStatus="" ItemType="" LocalizedControlType="window" Name="Mop1998" Orientation="None" ProcessId="11084" RuntimeId="42.1578230" x="0" y="0" width="1" height="1" CanMaximize="False" CanMinimize="True" IsModal="False" WindowVisualState="Normal" WindowInteractionState="ReadyForUserInteraction" IsTopmost="False" CanRotate="False" CanResize="False" CanMove="False" IsAvailable="True" />

Coming from a webdriver background, I can't see any ID's in there - no wonder it's not being able to find them or is that a misunderstanding on my part.

Is this app just too old for WinAppDriver? Should I give up?enter image description here


Solution

  • It's not the best option but I think you can use the sendkeys to access the OK button. Like Session.Keyboard.SendKeys(Keys.Alt + "o" + Keys.Alt); Since the access key is Alt+o. Alternately (IDK if this is gonna work) you can try to use the accessibilityId "3741054" as a accessibilityId like Session.FindElementByAccessibilityId("3741054");