Appium WebDriverException: Failed to Locate Application Window for My Own App
I'm running my application on windows EC2.
Getting error that: Failed to locate opened application window with appId: C:\Program Files (x86)\FolderPath\MyOwnApp.exe, and processId: 4016
public WindowsDriver<WindowsElement> GetDriver()
{
AppiumOptions appCapabilities = new AppiumOptions();
appCapabilities.AddAdditionalCapability("app", _winAppSession);
appCapabilities.AddAdditionalCapability("deviceName", "WindowsPC");
return new WindowsDriver<WindowsElement>(new Uri(_appiumDriverURI), appCapabilities);
}
_winAppSession is path which in this case is C:\\Program Files (x86)\\FolderPath\\MyOwnApp.exe
_appiumDriverURI is http://127.0.0.1:4723
This is giving the above mentioned error. After couple of seconds application launches with first showing the splash screen and then it opens the main screen.
Packages:
<package id="Selenium.Support" version="3.141.0" targetFramework="net472" />
<package id="Selenium.WebDriver" version="3.141.0" targetFramework="net472" />
It works when running on my system, but it fails most of the times when run in EC2.
https://github.com/microsoft/WinAppDriver/issues/1737#issuecomment-1161276608
@Shakevg When the application is started in local server and we are sending the commands using AWS SSM to execute automation using WinAppDriver.
Now after adding the fallback mentioned in in #1737. When i did a RDP into EC2 and then executed the automation, then it is working as expected and able to perform click actions. But when I don't do RDP into EC2 and execute the automation, then it is failing with error An unknown error occurred in the remote end while processing the command
@Shakevg
When I checked the Windows Application Driver logs, it shows that Driver was created successfully, but when trying to add username to the application it gives 200 but when trying to write value it is giving error.
Login happens in a popup windows with username and password.
Windows Application Driver listening for requests at: http://127.0.0.1:4723/
Press ENTER to exit.
==========================================
POST /session HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Content-Length: 163
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)
X-Idempotency-Key: d2aebd9a-05ce-4902-b8bc-3d05abc760da
HTTP/1.1 200 OK
Content-Length: 127
Content-Type: application/json
{"sessionId":"557C2584-73E9-45BB-95A6-8A0B24ACC143","status":0,"value":{"appTopLevelWindow":"1904e4","platformName":"Windows"}}
==========================================
POST /session/557C2584-73E9-45BB-95A6-8A0B24ACC143/element HTTP/1.1
Accept: application/json, image/png
Content-Length: 61
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)
X-Idempotency-Key: 5e2368db-dcf0-4276-95ec-dccb2e1a5e9b
{"using":"xpath","value":"//Edit[@AutomationId='_username']"}
HTTP/1.1 200 OK
Content-Length: 96
Content-Type: application/json
{"sessionId":"557C2584-73E9-45BB-95A6-8A0B24ACC143","status":0,"value":{"ELEMENT":"42.1508542"}}
==========================================
POST /session/557C2584-73E9-45BB-95A6-8A0B24ACC143/element/42.1508542/clear HTTP/1.1
Accept: application/json, image/png
Content-Length: 2
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)
X-Idempotency-Key: 10c612e6-d51e-434b-9643-530a6e9370d0
{}
HTTP/1.1 200 OK
Content-Length: 63
Content-Type: application/json
{"sessionId":"557C2584-73E9-45BB-95A6-8A0B24ACC143","status":0}
==========================================
POST /session/557C2584-73E9-45BB-95A6-8A0B24ACC143/element/42.1508542/value HTTP/1.1
Accept: application/json, image/png
Content-Length: 30
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)
X-Idempotency-Key: bf36c6c4-1992-4233-9671-a97faecce106
{"value":["My User Bot"]}
HTTP/1.1 500 Internal Error
Content-Length: 133
Content-Type: application/json
{"status":13,"value":{"error":"unknown error","message":"An unknown error occurred in the remote end while processing the command."}}
Is the login window a window created using winforms, WPF, UWP or the Microsoft authentication. Please also check if the username window is part of the same UI tree or a separate window.
Is the login window a window created using winforms, WPF, UWP or the Microsoft authentication. Please also check if the username window is part of the same UI tree or a separate window.
@anunay1 It is an external application based on the dependency used System.Windows.Forms. I think it is a winforms application. And username window is part of the same UI tree.
Xpath of the main UI Header: /Pane[@ClassName=\"#54321\"][@Name=\"Desktop 1\"]/Window[@Name=\"AppName\"][@AutomationId=\"ShellFormView\"]
Xpath of the Popup header: /Pane[@ClassName=\"#54321\"][@Name=\"Desktop 1\"]/Window[@Name=\"AppName\"][@AutomationId=\"ShellFormView\"]/Window[@Name=\"AppName Login\"][@AutomationId=\"LoginDialog\"]/TitleBar[@AutomationId=\"TitleBar\"]
Xpath of the username UI: /Pane[@ClassName=\"#54321\"][@Name=\"Desktop 1\"]/Window[@Name=\"AppName\"][@AutomationId=\"ShellFormView\"]/Window[@Name=\"AppName Login\"][@AutomationId=\"LoginDialog\"]/Edit[@AutomationId=\"_username\"]/Edit[starts-with(@ClassName,\"WindowsForms10\")]
Not to get how the WinAppDriver is able to run the automation when manual RDP is done in EC2 instance and fails to create winappdriver instance or not able to write the element when there is no manual RDP.
Can you check
https://community.fortra.com/kb-nav/kb-article/?id=548d72cc-68c3-eb11-bacc-000d3a1fe4c0&redirect=false
Also have a look at #147
Can you check
https://community.fortra.com/kb-nav/kb-article/?id=548d72cc-68c3-eb11-bacc-000d3a1fe4c0&redirect=false
Also have a look at #147
I have made the changes in the registry of windows EC2 as per section Configuration for all users in https://community.fortra.com/kb-nav/kb-article/?id=548d72cc-68c3-eb11-bacc-000d3a1fe4c0&redirect=false but I'm still getting the same error when there is no manual RDP in EC2.
It is able to clear the value but failing when it is trying to write the value in that element
Windows Application Driver listening for requests at: http://127.0.0.1:4723/
Press ENTER to exit.
==========================================
POST /session HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Content-Length: 162
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)
X-Idempotency-Key: 98858c1f-49d3-4cb7-990d-9d6ee1e64906
HTTP/1.1 200 OK
Content-Length: 126
Content-Type: application/json
{"sessionId":"64F734FF-887A-4434-9761-223776F9CBD3","status":0,"value":{"appTopLevelWindow":"700a4","platformName":"Windows"}}
==========================================
POST /session/64F734FF-887A-4434-9761-223776F9CBD3/element HTTP/1.1
Accept: application/json, image/png
Content-Length: 48
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)
X-Idempotency-Key: 65334bc2-1b95-4604-8ff7-b6434596222b
{"using":"accessibility id","value":"_username"}
HTTP/1.1 200 OK
Content-Length: 95
Content-Type: application/json
{"sessionId":"64F734FF-887A-4434-9761-223776F9CBD3","status":0,"value":{"ELEMENT":"42.393608"}}
==========================================
POST /session/64F734FF-887A-4434-9761-223776F9CBD3/element/42.393608/clear HTTP/1.1
Accept: application/json, image/png
Content-Length: 2
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)
X-Idempotency-Key: 448122b1-32c0-477e-8604-ec057e87ec18
{}
HTTP/1.1 200 OK
Content-Length: 63
Content-Type: application/json
{"sessionId":"64F734FF-887A-4434-9761-223776F9CBD3","status":0}
==========================================
POST /session/64F734FF-887A-4434-9761-223776F9CBD3/element/42.393608/value HTTP/1.1
Accept: application/json, image/png
Content-Length: 25
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)
X-Idempotency-Key: 529c3227-4094-465e-a399-3e647f0e02ff
{"value":["My User Bot"]}
HTTP/1.1 500 Internal Error
Content-Length: 133
Content-Type: application/json
{"status":13,"value":{"error":"unknown error","message":"An unknown error occurred in the remote end while processing the command."}}
==========================================
DELETE /session/64F734FF-887A-4434-9761-223776F9CBD3 HTTP/1.1
Accept: application/json, image/png
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)
X-Idempotency-Key: f95a26aa-e0bf-4c0f-98d6-f23d5a7776d2
HTTP/1.1 200 OK
Content-Length: 12
Content-Type: application/json
{"status":0}
==========================================
DELETE /session/ HTTP/1.1
Accept: application/json, image/png
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)
X-Idempotency-Key: c652b90f-83c3-4061-af92-db963c6b4c9f
HTTP/1.1 405 Method Not Allowed
Content-Length: 145
Content-Type: application/json
{"status":103,"value":{"error":"unknown method","message":"The requested command matched a known URL but did not match an method for that URL."}}
c
I did not understand any solution mentioned in #147
The error is very clear. Set value method is not supported. Use send keys instead
The error is very clear. Set value method is not supported. Use send keys instead
I have used send keys only still it is giving the same error, but the same code is working fine when there is no manual RDP to the AWS Windows EC2. I feel the issue is not with the code, or we need to make some configuration changes in ec2 or not sure.
Still getting same error : "An unknown error occurred in the remote end while processing the command."
WindowsElement usernameField = _windowsDriver.FindElementByAccessibilityId("_username");
usernameField.Clear();
usernameField.SendKeys("My User Bot");
I have worked on azure VM and it works fine. Not sure about ec2 better ask support from AWS. Also how do you know if the application is even launched when driver is initialised.I had a similar problem and i implemented screen recording and figured out the application is not launched successfully.
I have worked on azure VM and it works fine. Not sure about ec2 better ask support from AWS. Also how do you know if the application is even launched when driver is initialised.I had a similar problem and i implemented screen recording and figured out the application is not launched successfully.
Based on the above logs it seems that session it created and it is able to clear the existing value written in that element. But it is failing when it is trying to set the value to that element. Is there any way to know thrle exact root cause of that error, either by enabling debug logs of the winapp driver to know the exact cause, as it is returning generic error. And not able to figure out ehat can be the probable error.
Better implement screen recording. Depending on the language binding won't take much effort.
Usually I used to get this error either WinAppDriver.exe crashed or the system got locked.
@anunay1 I have made some changes and I have added CLI command Start-Process 'tscon' -ArgumentList 'rdp-tcp#0 /dest:console' -Verb runAs to attach console
After making this change before login it is able to perform click actions but after login it is able to find element but when trying to perform click action on the button it is showing error that element is not found. But the same is working when I login to EC2 instance.
It is able to find element //ToolBar[@Name='Modules'] but not able to find //Button[@Name='Payment Manager'] which is inside the Module. Not sure why the same is working when I login to EC2 instance.
==========================================
POST /session/F0DE19E2-A30C-4E35-ABA1-F06784BB9B91/element HTTP/1.1
Accept: application/json, image/png
Content-Length: 60
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)
X-Idempotency-Key: 197a9e11-c911-4ea1-a86a-5faff3699060
{"using":"xpath","value":"//Button[@AutomationId='_login']"}
HTTP/1.1 200 OK
Content-Length: 95
Content-Type: application/json
{"sessionId":"F0DE19E2-A30C-4E35-ABA1-F06784BB9B91","status":0,"value":{"ELEMENT":"42.458818"}}
==========================================
POST /session/F0DE19E2-A30C-4E35-ABA1-F06784BB9B91/element/42.458818/click HTTP/1.1
Accept: application/json, image/png
Content-Length: 2
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)
X-Idempotency-Key: bed96545-22ab-407b-ba7b-c20734cf9078
{}
HTTP/1.1 200 OK
Content-Length: 63
Content-Type: application/json
{"sessionId":"F0DE19E2-A30C-4E35-ABA1-F06784BB9B91","status":0}
==========================================
POST /session/F0DE19E2-A30C-4E35-ABA1-F06784BB9B91/elements HTTP/1.1
Accept: application/json, image/png
Content-Length: 54
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)
X-Idempotency-Key: da58ba1b-273e-42ba-b939-6f6022e546b2
{"using":"xpath","value":"//ToolBar[@Name='Modules']"}
HTTP/1.1 200 OK
Content-Length: 124
Content-Type: application/json
{"sessionId":"F0DE19E2-A30C-4E35-ABA1-F06784BB9B91","status":0,"value":[{"ELEMENT":"42b80c4c-5ef0-422b-873e-e96a112a4a3e"}]}
==========================================
GET /session/F0DE19E2-A30C-4E35-ABA1-F06784BB9B91/element/42b80c4c-5ef0-422b-873e-e96a112a4a3e/displayed HTTP/1.1
Accept: application/json, image/png
Cache-Control: no-cache
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)
X-Idempotency-Key: 82503ea3-857c-48f7-b614-8a860b38048a
HTTP/1.1 200 OK
Content-Length: 76
Content-Type: application/json
{"sessionId":"F0DE19E2-A30C-4E35-ABA1-F06784BB9B91","status":0,"value":true}
==========================================
POST /session/F0DE19E2-A30C-4E35-ABA1-F06784BB9B91/element HTTP/1.1
Accept: application/json, image/png
Content-Length: 61
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)
X-Idempotency-Key: 20d4140f-81e5-4795-b7f5-77d8c0aa4397
{"using":"xpath","value":"//Button[@Name='Payment Manager']"}
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."}}
==========================================
DELETE /session/F0DE19E2-A30C-4E35-ABA1-F06784BB9B91 HTTP/1.1
Accept: application/json, image/png
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)
X-Idempotency-Key: cd8c4494-2e1b-4c96-95b5-07e1ec451480
I got way to run the WinAppDriver, I have added CLI command Start-Process 'tscon' -ArgumentList 'rdp-tcp#0 /dest:console' -Verb runAs to attach console of my application. But with tscon, at times it fails to render some nested child elements if they are too nested.
Are you using xpath then it will be too slow. Try using some other methods like name, automation ID etc...