WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

Failed to locate opened application window with appId

Open Gaddale opened this issue 5 years ago • 19 comments

Hi All, I know this is repeated question, I have gone through the same issues logged my others and followed the solutions but some how I am not able to fix it. Request for help

Logs:

POST /session HTTP/1.1 Accept-Encoding: gzip Connection: Keep-Alive Content-Length: 475 Content-Type: application/json; charset=utf-8 Host: 127.0.0.1:4723 User-Agent: selenium/4.0.0-alpha-1 (java windows) { "desiredCapabilities": { "app": "C:\\Program Files (x86)\\XXX\\XXX.exe", "appArguments": "-internal -NoSplash", "platformName": "Windows", "deviceName": "Windows10" }, "capabilities": { "firstMatch": [ { "appium:app": "C:\\Program Files (x86)\\XXX\\XXX.exe", "appArguments": "-internal -NoSplash", "appium:deviceName": "Windows10", "platformName": "windows" } ] } } HTTP/1.1 500 Internal Error Content-Length: 190 Content-Type: application/json {"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: C:\\Program Files (x86)\\XXX\\XXX.exe, and processId: 11564"}}

Code:

DesiredCapabilities cap = new DesiredCapabilities(); cap.setCapability("app", "C:\\Program Files (x86)\\XXX\\XXX.exe"); cap.setCapability("platformName", "Windows"); cap.setCapability("deviceName", "Windows10"); cap.setCapability("appArguments", "-internal -NoSplash"); driver = new WindowsDriver(new URL("http://127.0.0.1:4723"), cap); Assert.assertNotNull(driver); driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);

The test is failing but the app is actually getting launched. Is there something I am doing wrong?

WindowsDriver (v1.2.1)

Regards, Nagaraj

Gaddale avatar Dec 30 '20 18:12 Gaddale

try cap.setCapability("app", "C:\\Program Files (x86)\\XXX\\XXX.exe");

thinski avatar Dec 31 '20 02:12 thinski

Hi Thinski, I have tried, but no luck..

Gaddale avatar Dec 31 '20 13:12 Gaddale

From the error it looks like your application has a splash screen

anunay1 avatar Jan 02 '21 12:01 anunay1

Yes it has splash screen, that is the reason I have added the appArguments as "appArguments": "-internal -NoSplash", And App is launching without splash screen.

Gaddale avatar Jan 02 '21 18:01 Gaddale

Which language binding are you using have u tried creating a root session and then switching to the opened window

anunay1 avatar Jan 02 '21 18:01 anunay1

I am using Java, I have not tried with root session. Generally I feel its good if I try to launch the application via driver instead of manually opening and switching from root session.

Gaddale avatar Jan 03 '21 13:01 Gaddale

Hi All, Any more suggestion's..no luck from myside

Gaddale avatar Jan 13 '21 16:01 Gaddale

Try with the below code: ` try { DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.setCapability("app", "Your APP"); appCapabilities.setCapability("platformName", "Windows"); appCapabilities.setCapability("deviceName", "WindowsPC"); session = new WindowsDriver<WindowsElement>(new URL(WindowsApplicationDriverUrl), appCapabilities); Thread.sleep(20000); session.findElementByName("Any element");// this will throw and exception

	} catch (Exception e) {

			if ("Failed to locate opened application window with appId"))
			{
				DesiredCapabilities capabilities = new DesiredCapabilities();
				capabilities.setCapability("app", "Root");
				desktopsession = new WindowsDriver<WindowsElement>(new
				URL(WindowsApplicationDriverUrl),capabilities);


				String topWindow = desktopsession.findElementByClassName("Your application Main WIndow 
                    classname").getAttribute("NativeWindowHandle");
				int MAWinHandleInt = Integer.parseInt(topWindow);
				String MAWinHandleHex = Integer.toHexString(MAWinHandleInt);

				DesiredCapabilities caps = new DesiredCapabilities();
				caps.setCapability("appTopLevelWindow", MAWinHandleHex);
				session = new WindowsDriver<WindowsElement>(new URL(WindowsApplicationDriverUrl), caps);

			}

} `

anunay1 avatar Jan 13 '21 16:01 anunay1

if the exception is different remove that if statement

anunay1 avatar Jan 13 '21 16:01 anunay1

@Gaddale Did the above solve the issue?

vagisha-nidhi195 avatar Mar 21 '22 15:03 vagisha-nidhi195

Check with the code snippet I provided I did not get any response form@Gaddale so my assumption he got it working

anunay1 avatar Mar 21 '22 15:03 anunay1

Or have you already tried my code.

anunay1 avatar Mar 21 '22 15:03 anunay1

Or have you already tried my code snippet

anunay1 avatar Mar 21 '22 15:03 anunay1

@anunay1 I have a UWP app which I am opening up using the same method. Whenever the remote machine is locked, I get this error. If I am on RDP with the remote machine (unlocked), this works fine. I tried getting the desktop session, and I do get my app in this session, but I do not get any NativeWindowHandle attribute in my page source. Is it not supposed to be in the page source?

One thing I could think of is to use the desktop session to emulate all my actions. But this doesn't sound like the best option. Is there anything else we could try? Would you know a method to get the native window handle ?

vagisha-nidhi195 avatar Mar 21 '22 16:03 vagisha-nidhi195

@vagisha-nidhi195 UI automation does not work when the system is locked. This holds good for any UI automation setup, disable the lock.

anunay1 avatar Mar 21 '22 16:03 anunay1

Also you can try the Solution if you want to run the automation in RDP minimized mode.

anunay1 avatar Mar 21 '22 16:03 anunay1

@anunay1 What do you mean by disable the lock ? I set my settings to "Never Lock", "Never sleep", I am still getting the same issue. Is there anything else to be done?

When I RDP into my computer, I don't see a lock screen anymore because I have configured autologon on my remote machine: https://docs.microsoft.com/en-us/sysinternals/downloads/autologon. But the test is still not working when I do not have an active RDP session. I guess this is my exact issue: https://github.com/microsoft/WinAppDriver/issues/147

vagisha-nidhi195 avatar Mar 21 '22 17:03 vagisha-nidhi195

"Whenever the remote machine is locked, I get this error." as per your comment. is the machine is in your office network it will be locked even if you set these setting, Raise an IT ticket and disable the system getting locked.

In case even if its not working then please set up a zoom call at [email protected]. because I really don't understand what you are trying to achieve.

anunay1 avatar Mar 21 '22 18:03 anunay1

@anunay1 Makes sense. Thanks for pointing that out! We are going to follow some advices on this https://github.com/microsoft/WinAppDriver/issues/147 thread to start an active session.

I know I shouldn't tag along and ask the questions here. Is there a way to start a WinAppDriver session without using admin mode? https://github.com/microsoft/WinAppDriver/blob/master/Docs/RunningOnRemoteMachine.md

If I give the local IP the initialisation fails with this error message.

Access denied: attempting to add Address 'http://X.x.x.x.X:4723/wd/hub'. Run as administrator to listen on an hostname other than localhost, or to listen on port 80.

Failed to initialize: 0x80004005

If I l use localhost or 127.0.0.1 the tests do not work remotely.

I am asking this because when we setup this up in CI/CD, I will be using a local system account and not an administrator account. I am sure this has been asked before but I haven't found a good answer.

Edit, I was able to do this with url reservation once in admin mode: https://stackoverflow.com/questions/14962334/httplistenerexception-access-denied-for-non-admins

vagisha-nidhi195 avatar Mar 24 '22 17:03 vagisha-nidhi195

Try with the below code: ` try { DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.setCapability("app", "Your APP"); appCapabilities.setCapability("platformName", "Windows"); appCapabilities.setCapability("deviceName", "WindowsPC"); session = new WindowsDriver(new URL(WindowsApplicationDriverUrl), appCapabilities); Thread.sleep(20000); session.findElementByName("Any element");// this will throw and exception

	} catch (Exception e) {

			if ("Failed to locate opened application window with appId"))
			{
				DesiredCapabilities capabilities = new DesiredCapabilities();
				capabilities.setCapability("app", "Root");
				desktopsession = new WindowsDriver<WindowsElement>(new
				URL(WindowsApplicationDriverUrl),capabilities);


				String topWindow = desktopsession.findElementByClassName("Your application Main WIndow 
                    classname").getAttribute("NativeWindowHandle");
				int MAWinHandleInt = Integer.parseInt(topWindow);
				String MAWinHandleHex = Integer.toHexString(MAWinHandleInt);

				DesiredCapabilities caps = new DesiredCapabilities();
				caps.setCapability("appTopLevelWindow", MAWinHandleHex);
				session = new WindowsDriver<WindowsElement>(new URL(WindowsApplicationDriverUrl), caps);

			}

} `

What should be put in the 8th line of given code (" Any element") ?

shruthibhatjm avatar Jan 31 '23 12:01 shruthibhatjm

Class name of your main window, you will get that in inspect.exe

anunay1 avatar Jan 31 '23 13:01 anunay1

Class name of your main window, you will get that in inspect.exe

session.findElementByName("Any element");

I am talking about this line of code. Over here do we need to put class name of the main window or the splash screen?

shruthibhatjm avatar Feb 01 '23 06:02 shruthibhatjm

Any element of the application?

anunay1 avatar Feb 01 '23 06:02 anunay1

can I use the name or class name of the splash screen?

shruthibhatjm avatar Feb 01 '23 06:02 shruthibhatjm

desktopsession = new WindowsDriver<WindowsElement>(new URL(WindowsApplicationDriverUrl),capabilities);

is it desktopsession of session? because you have used session in the other part

shruthibhatjm avatar Feb 01 '23 06:02 shruthibhatjm

can I use the name or class name of the splash screen?

No.

anunay1 avatar Feb 01 '23 06:02 anunay1

desktopsession = new WindowsDriver<WindowsElement>(new URL(WindowsApplicationDriverUrl),capabilities);

is it desktopsession of session? because you have used session in the other part

It's a seperate session?

anunay1 avatar Feb 01 '23 06:02 anunay1

desktopsession should be initialized first right? and ("Any Element") can be an element on any screen like login screen too?

shruthibhatjm avatar Feb 01 '23 06:02 shruthibhatjm

Which block try or catch?

anunay1 avatar Feb 01 '23 07:02 anunay1

in try block, in this line of code session.findElementByName("Any element");// this will throw and exception

shruthibhatjm avatar Feb 01 '23 07:02 shruthibhatjm