WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

WinAppDriver couldn't find the elements of WPF application

Open anilr945 opened this issue 6 years ago • 40 comments

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");
    

anilr945 avatar Nov 04 '19 06:11 anilr945

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);

BalarajAdappa avatar Nov 04 '19 09:11 BalarajAdappa

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."}}.

anilr945 avatar Nov 05 '19 04:11 anilr945

Can you share the server logs

anunay1 avatar Nov 05 '19 04:11 anunay1

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."}}

anilr945 avatar Nov 05 '19 05:11 anilr945

Are you copy pasteing this id from inspect or hand doing it, try copy pasteing from inspect.

anunay1 avatar Nov 05 '19 05:11 anunay1

I got it from inspect itself.

anilr945 avatar Nov 05 '19 06:11 anilr945

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();

anilr945 avatar Nov 05 '19 12:11 anilr945

are you starting the server as admin

anunay1 avatar Nov 06 '19 13:11 anunay1

yes

anilr945 avatar Nov 07 '19 05:11 anilr945

Can we have a hangout call

anunay1 avatar Nov 07 '19 05:11 anunay1

yes we can

anilr945 avatar Nov 07 '19 06:11 anilr945

Your i'd

anunay1 avatar Nov 07 '19 06:11 anunay1

dropped a mail [email protected]

anunay1 avatar Nov 07 '19 06:11 anunay1

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  

anunay1 avatar Nov 07 '19 11:11 anunay1

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.

vijay-kr-bandi avatar Nov 07 '19 23:11 vijay-kr-bandi

If inspect cannot find the element WAD will not find, is the wpf window the child of win form

anunay1 avatar Nov 08 '19 03:11 anunay1

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.

anilr945 avatar Nov 08 '19 04:11 anilr945

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

vijay-kr-bandi avatar Nov 08 '19 14:11 vijay-kr-bandi

Then please ask your developers to provide you automation ids or else log a bug with inspect,

anunay1 avatar Nov 08 '19 14:11 anunay1

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.

vijay-kr-bandi avatar Nov 08 '19 14:11 vijay-kr-bandi

Is inspect able to find the element

anunay1 avatar Nov 08 '19 15:11 anunay1

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

vijay-kr-bandi avatar Nov 08 '19 15:11 vijay-kr-bandi

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?

anilr945 avatar Nov 18 '19 11:11 anilr945

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?

docian avatar Mar 08 '20 12:03 docian

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.

evansct avatar Jul 30 '20 13:07 evansct

Can you link exactly what Inspect shows when inspecting the password text box?

PandaMagnus avatar Jul 30 '20 18:07 PandaMagnus

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.

bindupatnaik avatar May 10 '21 01:05 bindupatnaik

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.

TeodoraGK avatar Aug 23 '21 05:08 TeodoraGK

@bindupatnaik I have sent you the hangout invitation. Let me know if we can have the call now.

anunay1 avatar Aug 23 '21 11:08 anunay1

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.

Rehan991 avatar Dec 06 '21 01:12 Rehan991