Any element attribute gives same error "org.openqa.selenium.NoSuchWindowException: java.lang.ClassCastException: java.base/java.util.HashMap cannot be cast to java.base/java.lang.String "
Code Snippet
// Check if Printer under test is already selected if not then select it
PrinterListComboBox = (WindowsElement) WinWordSession.findElementByClassName("NetUIDropdownAnchor");
Assert.assertNotNull(PrinterListComboBox);
if(PrinterListComboBox.getText().contentEquals(ptr_name)) {
log.info("Desired printer =>" +ptr_name+" is already selected");
}else {
PrinterListComboBox.findElementByName(ptr_name).click();
log.info("Selected desired printer "+ptr_name+"from printers list dropdown");
}
Inspect details

WinAppDriver Log
2018-03-26 21:57:47:997 - info: [WinAppDriver] [STDOUT]
2018-03-26 21:57:47:997 - info: [WinAppDriver] [STDOUT] {"sessionId":"7B74BE39-8747-4347-9F2C-085214C3D332","status":0}
2018-03-26 21:57:47:997 - info: [debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"7B74BE39-8747-4347-9F2C-085214C3D332","status":0}
2018-03-26 21:57:47:997 - info: [JSONWP Proxy] Replacing sessionId 7B74BE39-8747-4347-9F2C-085214C3D332 with 84ba24ee-338a-483d-af99-e5544060cdd6
2018-03-26 21:57:47:997 - info: [HTTP] <-- POST /wd/hub/session/84ba24ee-338a-483d-af99-e5544060cdd6/keys 200 146 ms - 63
2018-03-26 21:57:49:032 - info: [HTTP] --> DELETE /wd/hub/session/84ba24ee-338a-483d-af99-e5544060cdd6/window {}
2018-03-26 21:57:49:032 - info: [MJSONWP] Driver proxy active, passing request on via HTTP proxy
2018-03-26 21:57:49:032 - info: [debug] [JSONWP Proxy] Proxying [DELETE /wd/hub/session/84ba24ee-338a-483d-af99-e5544060cdd6/window] to [DELETE http://127.0.0.1:4725/wd/hub/session/7B74BE39-8747-4347-9F2C-085214C3D332/window] with body: {}
2018-03-26 21:57:49:047 - info: [WinAppDriver] [STDOUT]
2018-03-26 21:57:49:047 - info: [WinAppDriver] [STDOUT]
2018-03-26 21:57:49:047 - info: [WinAppDriver] [STDOUT] ==========================================
2018-03-26 21:57:49:047 - info: [WinAppDriver] [STDOUT] DELETE /wd/hub/session/7B74BE39-8747-4347-9F2C-085214C3D332/window HTTP/1.1
2018-03-26 21:57:49:047 - info: [WinAppDriver] [STDOUT] Accept: /
2018-03-26 21:57:49:047 - info: [WinAppDriver] [STDOUT] Connection: keep-alive
2018-03-26 21:57:49:047 - info: [WinAppDriver] [STDOUT] Content-Length: 2
2018-03-26 21:57:49:047 - info: [WinAppDriver] [STDOUT] Content-Type: application/json
2018-03-26 21:57:49:063 - info: [WinAppDriver] [STDOUT] Host: 127.0.0.1:4725
2018-03-26 21:57:49:063 - info: [WinAppDriver] [STDOUT] User-Agent: appium
2018-03-26 21:57:49:063 - info: [WinAppDriver] [STDOUT]
2018-03-26 21:57:49:063 - info: [WinAppDriver] [STDOUT] {}
2018-03-26 21:57:49:063 - info: [WinAppDriver] [STDOUT] HTTP/1.1 200 OK
2018-03-26 21:57:49:063 - info: [WinAppDriver] [STDOUT] Content-Length: 63
2018-03-26 21:57:49:063 - info: [WinAppDriver] [STDOUT] Content-Type: application/json
2018-03-26 21:57:49:063 - info: [WinAppDriver] [STDOUT]
2018-03-26 21:57:49:063 - info: [WinAppDriver] [STDOUT] {"sessionId":"7B74BE39-8747-4347-9F2C-085214C3D332","status":0}
2018-03-26 21:57:49:078 - info: [debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"7B74BE39-8747-4347-9F2C-085214C3D332","status":0}
2018-03-26 21:57:49:078 - info: [JSONWP Proxy] Replacing sessionId 7B74BE39-8747-4347-9F2C-085214C3D332 with 84ba24ee-338a-483d-af99-e5544060cdd6
2018-03-26 21:57:49:078 - info: [HTTP] <-- DELETE /wd/hub/session/84ba24ee-338a-483d-af99-e5544060cdd6/window 200 48 ms - 63
2018-03-26 21:57:49:094 - info: [HTTP] --> POST /wd/hub/session/29e2081d-5f52-4dbd-9332-1766824b576e/element {"using":"class name","value":"NetUIDropdownAnchor"}
2018-03-26 21:57:49:094 - info: [MJSONWP] Driver proxy active, passing request on via HTTP proxy
2018-03-26 21:57:49:094 - info: [debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/29e2081d-5f52-4dbd-9332-1766824b576e/element] to [POST http://127.0.0.1:4724/wd/hub/session/D724DC79-C6EF-48E0-9958-FCABF36EBA1F/element] with body: {"using":"class name","value":"NetUIDropdownAnchor"}
2018-03-26 21:57:49:094 - info: [WinAppDriver] [STDOUT]
2018-03-26 21:57:49:094 - info: [WinAppDriver] [STDOUT]
2018-03-26 21:57:49:094 - info: [WinAppDriver] [STDOUT] ==========================================
2018-03-26 21:57:49:094 - info: [WinAppDriver] [STDOUT] POST /wd/hub/session/D724DC79-C6EF-48E0-9958-FCABF36EBA1F/element HTTP/1.1
2018-03-26 21:57:49:094 - info: [WinAppDriver] [STDOUT] Accept: /
2018-03-26 21:57:49:094 - info: [WinAppDriver] [STDOUT] Connection: keep-alive
2018-03-26 21:57:49:094 - info: [WinAppDriver] [STDOUT] Content-Length: 52
2018-03-26 21:57:49:094 - info: [WinAppDriver] [STDOUT] Content-Type: application/json
2018-03-26 21:57:49:094 - info: [WinAppDriver] [STDOUT] Host: 127.0.0.1:4724
2018-03-26 21:57:49:094 - info: [WinAppDriver] [STDOUT] User-Agent: appium
2018-03-26 21:57:49:094 - info: [WinAppDriver] [STDOUT]
2018-03-26 21:57:49:110 - info: [WinAppDriver] [STDOUT] {"using":"class name","value":"NetUIDropdownAnchor"}
2018-03-26 21:57:49:110 - info: [WinAppDriver] [STDOUT] HTTP/1.1 400 Bad Request
2018-03-26 21:57:49:110 - info: [WinAppDriver] [STDOUT] Content-Length: 102
2018-03-26 21:57:49:110 - info: [WinAppDriver] [STDOUT] Content-Type: application/json
2018-03-26 21:57:49:110 - info: [WinAppDriver] [STDOUT]
2018-03-26 21:57:49:110 - info: [WinAppDriver] [STDOUT] {"status":23,"value":{"error":"no such window","message":"Currently selected window has been closed"}}
2018-03-26 21:57:49:110 - error: [MJSONWP] Encountered internal error running command: {"w3cStatus":400,"jsonwp":{"status":23,"value":{"error":"no such window","message":"Currently selected window has been closed"}}} ProxyRequestError: Could not proxy command to remote server. Original error: 400 - {"status":23,"value":{"error":"no such window","message":"Currently selected window has been closed"}}
at JWProxy.proxy$ (C:\Users\E2E Lab\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:152:13)
at tryCatch (C:\Users\E2E Lab\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\E2E Lab\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (C:\Users\E2E Lab\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (C:\Users\E2E Lab\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
at
Looks like I am getting the same error for any session.findElement calls like ByName, ByAccessbilityId etc.) for MS word app (MS Office 365 ProPlus). Is this a defect in WinApp Driver?
Got solutions after referring multiple gitHub issues.
An explanation for the solution: Once WINWORD.EXE launches then it just opens test file but does not own main application process to perform any operations so we need to wait and then follow below steps to get session of Main window (that owns the application) then perform any click on MS Word Ribbons.
- Create a session for your application (this will launch the process and the main window even though locating window may fail)
- Wait until your application window shows up
- Create another session through which you can locate the application window you are interested (relaunched MS app again)
- Retrieve the window handle of the application window you located
- Create a session by providing the application top-level window above
This solved my problem but these tricks are not easy to know as MS word won't even have splash screen so It always seems that initial screen owns the application.
Hi, I am able to launch word application after that i am unable to perform any operation on the application. 1.Launch the word application 2.click on blank word document 3.enter some text and save the document I am unable to click on the blank document, tried few ways suggested by you and from the winappdriver forums. Error Stack Trace: org.openqa.selenium.NoSuchWindowException: Currently selected window has been closed (WARNING: The server did not provide any stacktrace information) Any suggestions would be appreciated. Thanks in advance...
Hi @lokeshparcel,
Typically Microsoft Office applications launch a splash screen that is indeed a valid UI component/window that Windows Application Driver can automate against. In this case however, you are actually interested on the main window that appears after the splash screen is dismissed. As the WinAppDriver session you used to launch the Microsoft Word could still be pointing to the dismissed splash screen window, you would need to switch to the main window. While there is a few options to do this, the most reliable and generic approach is to use the Desktop Session to locate the main window and attach to it.
You can also refer to the example I provided on the following similar issue: https://github.com/Microsoft/WinAppDriver/issues/392#issuecomment-412728379