WinAppDriver
WinAppDriver copied to clipboard
WinAppDriver couldn't find the elements of WPF application
I am new to automation and I am trying to automate the WPF application using WinAppDriver with C#. I am able to load the application but getting the error like {"An element could not be located on the page using the given search parameters."} while trying to find the element with Name/AccessibilityId even after keeping the wait time.
See below:
POST /session/09551C9F-CF20-4C2B-A900-F17D2483F9D8/element HTTP/1.1 Accept: application/json, image/png Content-Length: 45 Content-Type: application/json;charset=utf-8 Host: 127.0.0.1:4723
{"using":"accessibility id","value":"TxtPwd"} HTTP/1.1 404 Not Found Content-Length: 139 Content-Type: application/json
{"status":7,"value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters."}}
I don't know what is happening. Any suggestions?
I did like:
-
check for the elements and automation-id/name of element through inspect tool
-
set developer mode active
-
wait time before finding the element
var aDesiredCapabilities = new DesiredCapabilities(); aDesiredCapabilities.SetCapability("app", @"PathToApplication"); aDesiredCapabilities.SetCapability("deviceName", "Windows 10"); var aWindow = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), aDesiredCapabilities); aWindow.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); aWindow.FindElementByAccessibilityId("TxtPwd").SendKeys("qwerty"); aWindow.FindElementByAccessibilityId("TxtUser").SendKeys("123456"); aWindow.FindElementByAccessibilityId("Clear").Click(); aWindow.FindElementByAccessibilityId("TxtPwd").SendKeys("qwerty"); aWindow.FindElementByAccessibilityId("TxtUser").SendKeys("123456"); aWindow.FindElementByAccessibilityId("Login");
Are you giving right path @"PathToApplication" ?? if yes, is it creating session ?
when you debug are you executing this below line successfully?, which means it has to create session.
var aWindow = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), aDesiredCapabilities);
Yes, I gave the correct path and it is launching the application. And, I am getting the title of the application as well. This means that session is created successfully. When I try to find an element, getting an exception {"status":7,"value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters."}}.
Can you share the server logs
POST /session/09551C9F-CF20-4C2B-A900-F17D2483F9D8/element HTTP/1.1 Accept: application/json, image/png Content-Length: 45 Content-Type: application/json;charset=utf-8 Host: 127.0.0.1:4723
{"using":"accessibility id","value":"TxtPwd"} HTTP/1.1 404 Not Found Content-Length: 139 Content-Type: application/json
{"status":7,"value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters."}}
Are you copy pasteing this id from inspect or hand doing it, try copy pasteing from inspect.
I got it from inspect itself.
The same thing is happening with Calculator application also. Not able to automate the number clicks. Please see below:
var aAppiumOptions = new AppiumOptions();
aAppiumOptions.AddAdditionalCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
aAppiumOptions.AddAdditionalCapability("deviceName", "WindowsPC");
var Session = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), aAppiumOptions);
Assert.IsNotNull(Session);
Assert.AreEqual("Calculator", Session.Title);
Session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
Session.FindElementByAccessibilityId("num5Button").Click();
Session.FindElementByAccessibilityId("plusButton").Click();
Session.FindElementByAccessibilityId("num7Button").Click();
Session.FindElementByAccessibilityId("equalButton").Click();
are you starting the server as admin
yes
Can we have a hangout call
yes we can
Your i'd
dropped a mail [email protected]
Dude you are confused between name and AccessibilityId, you are using name with accessibility which will never work. This is the correct code. [TestMethod] public void Calculator() { if (session == null) { // Set the capabilities for parent window. DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", _calApp);
appCapabilities.SetCapability("deviceName", "WindowsPC");
session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
// Calculator window.
//var calculatorWindow = session.FindElementByName("Calculator");
session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(7);
//Thread.Sleep(TimeSpan.FromSeconds(10));
//var aTitleBar = session.FindElementByAccessibilityId("TitleBar");
//aTitleBar.FindElementByAccessibilityId("Maximize").Click();
//aTitleBar.FindElementByAccessibilityId("Maximize").Click();
//aTitleBar.FindElementByAccessibilityId("Maximize").Click();
session.FindElementByName("Seven").Click();
session.FindElementByName("Plus").Click();
session.FindElementByAccessibilityId("num6Button").Click();
session.FindElementByName("Equals").Click();
}
}
This chart will explain:
| Client API | Locator Strategy | Matched Attribute in inspect.exe | Example |
|---|---|---|---|
| FindElementByAccessibilityId | accessibility id | AutomationId | AppNameTitle |
| FindElementByClassName | class name | ClassName | TextBlock |
| FindElementById | id | RuntimeId (decimal) | 42.333896.3.1 |
| FindElementByName | name | Name | Calculator |
| FindElementByTagName | tag name | LocalizedControlType (upper camel case) | Text |
| FindElementByXPath | xpath | Any |
I am also facing similar problem.
The application has two parts . Initilly all the actions are performed in windows forms, this works well. Finding elements using name/accessibilityid is successful.
later wpf usercontrol will be loaded into windows form(System.Windows.Forms.Integration.ElementHost). Once the wpf controls are loaded, no elements can be found. Even the inspector couldn't find the name/automationid.
If inspect cannot find the element WAD will not find, is the wpf window the child of win form
Dude you are confused between name and AccessibilityId, you are using name with accessibility which will never work. This is the correct code. [TestMethod] public void Calculator() { if (session == null) { // Set the capabilities for parent window. DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", _calApp); appCapabilities.SetCapability("deviceName", "WindowsPC"); session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities); // Calculator window. //var calculatorWindow = session.FindElementByName("Calculator"); session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(7); //Thread.Sleep(TimeSpan.FromSeconds(10)); //var aTitleBar = session.FindElementByAccessibilityId("TitleBar"); //aTitleBar.FindElementByAccessibilityId("Maximize").Click(); //aTitleBar.FindElementByAccessibilityId("Maximize").Click(); //aTitleBar.FindElementByAccessibilityId("Maximize").Click(); session.FindElementByName("Seven").Click(); session.FindElementByName("Plus").Click(); session.FindElementByAccessibilityId("num6Button").Click(); session.FindElementByName("Equals").Click(); } }This chart will explain:
Client API Locator Strategy Matched Attribute in inspect.exe Example FindElementByAccessibilityId accessibility id AutomationId AppNameTitle FindElementByClassName class name ClassName TextBlock FindElementById id RuntimeId (decimal) 42.333896.3.1 FindElementByName name Name Calculator FindElementByTagName tag name LocalizedControlType (upper camel case) Text FindElementByXPath xpath Any
For me, session.FindElementByName("Seven").Click(); this line itself is throwing an exception. And I tried Name and AccessibilityID with exact values also but still it didn't work.
If inspect cannot find the element WAD will not find, is the wpf window the child of win form
Yes , its child of win form
Then please ask your developers to provide you automation ids or else log a bug with inspect,
Then please ask your developers to provide you automation ids or else log a bug with inspect,
automation id(AutomationProperties.AutomationId) is already set , but still can't access t.
Is inspect able to find the element
Is inspect able to find the element
No. The control is a tab control , it always shows automationid as id of tabcontrol whatever the element is selected inside tabcontrol. Winappdriver fails to find the tabcontrol using the automationid from inspect: automationid : Tabautomationid Clasname : TabControl Frameworkid : wpf
Dude you are confused between name and AccessibilityId, you are using name with accessibility which will never work. This is the correct code. [TestMethod] public void Calculator() { if (session == null) { // Set the capabilities for parent window. DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", _calApp); appCapabilities.SetCapability("deviceName", "WindowsPC"); session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities); // Calculator window. //var calculatorWindow = session.FindElementByName("Calculator"); session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(7); //Thread.Sleep(TimeSpan.FromSeconds(10)); //var aTitleBar = session.FindElementByAccessibilityId("TitleBar"); //aTitleBar.FindElementByAccessibilityId("Maximize").Click(); //aTitleBar.FindElementByAccessibilityId("Maximize").Click(); //aTitleBar.FindElementByAccessibilityId("Maximize").Click(); session.FindElementByName("Seven").Click(); session.FindElementByName("Plus").Click(); session.FindElementByAccessibilityId("num6Button").Click(); session.FindElementByName("Equals").Click(); } }This chart will explain: Client API Locator Strategy Matched Attribute in inspect.exe Example FindElementByAccessibilityId accessibility id AutomationId AppNameTitle FindElementByClassName class name ClassName TextBlock FindElementById id RuntimeId (decimal) 42.333896.3.1 FindElementByName name Name Calculator FindElementByTagName tag name LocalizedControlType (upper camel case) Text FindElementByXPath xpath Any
For me, session.FindElementByName("Seven").Click(); this line itself is throwing an exception. And I tried Name and AccessibilityID with exact values also but still it didn't work.
Does anyone have idea/suggestion how to make it work?
i've encountered the same issue: when i'm switching from wpf to winfgorm cannot find any element. inspect is providing the properties of elements but WAD is not able to control them. i've tried to switchTo window that has that certain handle but it is throwing an exception. any idea?
I too am having a similar issue. The element is visible on inspect.exe, however WAD doesn't seem to be able to find it. I get the same error as the author {"An element could not be located on the page using the given search parameters."}. I posted an issue myself because I didn't see this one: Appium not finding WPF elements #1249. There's some screenshots there explaining my issue a bit more.
Can you link exactly what Inspect shows when inspecting the password text box?
any update on this issue? i am also facing a similar issue where inspect tool is not identifying elements that are inside grid. Same element is getting identified using TestComplete object spy. I can have a hangout call to show the issue. here is my id [email protected]. if this is a limitation with inspect tool, can anyone suggest any other tools i can use to identify elements in WPF xceed Grid elements that will be helpful. FYI, the UIRecorder is not identifying elements inside Grid. This tool is also not helpful either.
Hello! Is there any update on this issue? I will be very grateful if you share! I tried everything I could find on the topic, but I could not locate the elements.
@bindupatnaik I have sent you the hangout invitation. Let me know if we can have the call now.
Hey I am using winappdriver to test windows based applications but it is a kinda browser with a launcher screen, able to use winappdriver on launcher screen to automate it but after launching the application then on Every part of application like i want to click some features, anything but it didn't find the elements and gives the error. An element could not be located on the page usingthe given search.