Failed to locate opened application window with appId
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
try cap.setCapability("app", "C:\\Program Files (x86)\\XXX\\XXX.exe");
Hi Thinski, I have tried, but no luck..
From the error it looks like your application has a splash screen
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.
Which language binding are you using have u tried creating a root session and then switching to the opened window
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.
Hi All, Any more suggestion's..no luck from myside
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);
}
} `
if the exception is different remove that if statement
@Gaddale Did the above solve the issue?
Check with the code snippet I provided I did not get any response form@Gaddale so my assumption he got it working
Or have you already tried my code.
Or have you already tried my code snippet
@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 UI automation does not work when the system is locked. This holds good for any UI automation setup, disable the lock.
Also you can try the Solution if you want to run the automation in RDP minimized mode.
@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
"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 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
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") ?
Class name of your main window, you will get that in inspect.exe
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?
Any element of the application?
can I use the name or class name of the splash screen?
desktopsession = new WindowsDriver<WindowsElement>(new URL(WindowsApplicationDriverUrl),capabilities);
is it desktopsession of session? because you have used session in the other part
can I use the name or class name of the splash screen?
No.
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?
desktopsession should be initialized first right? and ("Any Element") can be an element on any screen like login screen too?
Which block try or catch?
in try block, in this line of code session.findElementByName("Any element");// this will throw and exception