Winappdriver: Failed to locate opened application window with appId: C:\Users\User\Desktop\xxx\xxx\xxx.exe, and processId: 14776

Created on 9 May 2019  ·  14Comments  ·  Source: microsoft/WinAppDriver

I have a Windows Application with one single window (no splash screen, pop-ups or the like) which was working until recently. I've made no changes to the setup method, and cannot track down the cause of the issue. Both Task Manager and inspect.exe see the same process id as in the error message.

WinApp protocol:

POST /session HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Content-Length: 185
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723


HTTP/1.1 500 Internal Error
Content-Length: 263
Content-Type: application/json

{"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: C:\\Users\\user\\Desktop\\xxx\\xxx\\xxx\\xxx.exe, and processId: 14776"}}

My code:

public WindowsDriver<WindowsElement> CreateNewSession(string appId, string argument = null)
        {
            // Create a new session
            DesiredCapabilities appCapabilities = new DesiredCapabilities();
            appCapabilities.SetCapability("app", appId);
            return new WindowsDriver<WindowsElement>(new Uri(TestConfig.WindowsApplicationDriverUrl), appCapabilities);
        }

...where AppID is the path to my executable.

The app seems to hang up and refuse to launch until the test has failed, then is released and launches. It's as if some process is hanging on to it. I have tried adding an implicit wait using TimeSpan when I create the new session, but the same problem still occurs (it just takes longer to happen).

As I said, this worked for weeks previously, and I've pored over any changes and cannot find any possible cause of the issue.

NOTE: my coworker pulled from the same branch, ran the same test, and it passes. Which just made me more frustrated.

Most helpful comment

Try to include below capability which solved my issue of Failed to locate opened application window with appId"xxx" and process "xxx"

My exe file present in C:\Program Files\MT

appCapabilities.SetCapability("appWorkingDir", "C:\Program Files\MT");

All 14 comments

Try to create another desktop session and find the window of your application in that session instead of the one which you've used to launch the application.

Thank you for the quick response!

I have created a desktop session, and if I manually launch the application before I run, I do see my application window. However, because I have an entire suite of tests that was written by making a session for my actual app, I now have to update everything to use a child of the desktop session.

This seems a bit hacky, especially since I would be changing my coworker's tests, and my coworker does not have the same issue as me. If I could figure out what started causing this issue out of the blue it would be a much better solution.

My coworker and I have the same versions of WinAppDriver, VS, and everything else seems to be the same. And as I said, it was working as expected on my machine for months before it all of the sudden didn't.

For anyone reading in the future, I've created what I hope is a temporary branch with a workaround using a desktop session, which looks like this:

DesiredCapabilities desktopCapabilities = new DesiredCapabilities();
            desktopCapabilities.SetCapability("platformName", "Windows");
            desktopCapabilities.SetCapability("app", "Root");
            desktopCapabilities.SetCapability("deviceName", "WindowsPC");
            WindowsDriver<WindowsElement> session = new WindowsDriver<WindowsElement>(new Uri(TestConfig.WindowsApplicationDriverUrl), desktopCapabilities);

            //  Grab the application window, which is a child of the Desktop window
            var ApplicationWindow = session.FindElementByName("ApplicationName");
            ApplicationWindow.Click();
            var ApplicationSessionHandle = ApplicationWindow.GetAttribute("NativeWindowHandle");
            ApplicationSessionHandle = (int.Parse(ApplicationSessionHandle)).ToString("x"); //Convert to hex

            DesiredCapabilities appCapabilities = new DesiredCapabilities();
            appCapabilities.SetCapability("appTopLevelWindow", ApplicationSessionHandle);
            var ApplicationSession = new WindowsDriver<WindowsElement>(new Uri(TestConfig.WindowsApplicationDriverUrl), appCapabilities);

            return ApplicationSession;

This does not launch my app, which I have to do manually before running the tests now.

Strange it's an error for you and not your co-worker. What else may have changed on your machine - did Windows recently update?

Very strange! Not only that, but on old branches it still works on my machine. Yet like I say, it works all the time for my coworker, no matter the branch. The only code difference is in the application, nothing involving WAD or test setup has changed.

So the issue seems to be localized the new branch, on my machine only. We have identical versioning on every piece of relevant software.

Windows has not updated, but now that you mention it, I did do a BIOS update recently. I wonder if that had some unforeseen effect. I wouldn't see how that would be possible though, seeing as it still runs on old branches.

This may be something I'm going to have to find out on my own, seeing as it is so localized.
Thank you for your help! If I can figure out the issue I will update.

Glad that my answer helped somehow. Maybe your coworker updated his Appium. Try updating your Appium from npm.

Updating Appium fixed the issue! @naeemakram you were a great help.

You're welcome Brandon :)

更新Appium解决了该问题!@naeemakram,您的帮助很大。
Appium What version, I also have this problem, updated or this error

I'm not entirely sure which version we were working with at that time. Just run the npm update package.

Try to include below capability which solved my issue of Failed to locate opened application window with appId"xxx" and process "xxx"

My exe file present in C:\Program Files\MT

appCapabilities.SetCapability("appWorkingDir", "C:\Program Files\MT");

Interesting insight Balaji... Will keep it in mind for future projects...

Try to include below capability which solved my issue of Failed to locate opened application window with appId"xxx" and process "xxx"

My exe file present in C:\Program Files\MT

appCapabilities.SetCapability("appWorkingDir", "C:\Program Files\MT");

Balaji's approach solved my issue!

Try to include below capability which solved my issue of Failed to locate opened application window with appId"xxx" and process "xxx"

My exe file present in C:\Program Files\MT

appCapabilities.SetCapability("appWorkingDir", "C:\Program Files\MT");

This helped me.. !! Thank you !!

Was this page helpful?
0 / 5 - 0 ratings