-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to identify the UI when we run the script through command prompt #1980
Comments
The error says that it is unable to find the opened window, please try to add some delay before you create a session on the opened window. |
I'm curious, are you using APPIUM? Am I right? |
This happens only if I launch and attach my application, otherwise it works perfectly fine when I launch the application through the driver itself |
No no, I am using appium's package only - "Microsoft.WinAppDriver.Appium.WebDriver" |
It's weird. Can you schedule a zoom call? |
Launch the application
System.Diagnostics.Process.Start("Application.Exe Path");
Create a root desktop session as mentioned in the documentation
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", "Root");
DesktopSession = new WindowsDriver(new Uri("http://127.0.0.1:4723"), appCapabilities);
var CortanaWindow = DesktopSession.FindElementByName("Cortana");
var CortanaTopLevelWindowHandle = CortanaWindow.GetAttribute("NativeWindowHandle");
CortanaTopLevelWindowHandle = (int.Parse(CortanaTopLevelWindowHandle)).ToString("x"); // Convert to Hex
// Create session by attaching to Cortana top level window
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("appTopLevelWindow", CortanaTopLevelWindowHandle);
CortanaSession = new WindowsDriver(new Uri(WindowsApplicationDriverUrl), appCapabilities);
When I run this particular script through visual studio's developer terminal/powershell, it works fine, even when I trigger the scripts through test explorer it works fine.
But when I try to run the script through an individual command prompt instance outside the visual studio, it fails to identify the application session
The API calls that happen when I run through a command prompt instance
POST /session HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Content-Length: 63
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
{"desiredCapabilities":{"app":"Root","platformName":"Windows"}}
HTTP/1.1 200 OK
Content-Length: 111
Content-Type: application/json
{"sessionId":"sessionID","status":0,"value":{"app":"Root","platformName":"Windows"}}
==========================================
POST /session/sessionID/element HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Content-Length: 41
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
{"using":"name","value":"appname"}
HTTP/1.1 200 OK
Content-Length: 99
Content-Type: application/json
{"sessionId":"sessionID","status":0,"value":{"ELEMENT":"42.12345.6.78"}}
==========================================
GET /session/sessionId/element/42.12345.6.78/attribute/NativeWindowHandle HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Host: 127.0.0.1:4723
HTTP/1.1 200 OK
Content-Length: 75
Content-Type: application/json
{"sessionId":"sessionId","status":0,"value":"0"}
==========================================
POST /session HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Content-Length: 74
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
{"desiredCapabilities":{"appTopLevelWindow":"0","platformName":"Windows"}}
HTTP/1.1 400 Bad Request
Content-Length: 131
Content-Type: application/json
{"status":23,"value":{"error":"no such window","message":"Cannot find active window specified by capabilities: appTopLevelWindow"}}
POST /session HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Content-Length: 63
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
{"desiredCapabilities":{"app":"Root","platformName":"Windows"}}
HTTP/1.1 200 OK
Content-Length: 111
Content-Type: application/json
{"sessionId":"sessionId","status":0,"value":{"app":"Root","platformName":"Windows"}}
==========================================
POST /session/sessionId/element HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Content-Length: 41
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
{"using":"name","value":"App name"}
HTTP/1.1 200 OK
Content-Length: 96
Content-Type: application/json
{"sessionId":"sessionId","status":0,"value":{"ELEMENT":"42.1234567"}}
==========================================
GET /session/sessionId/element/42.1234567/attribute/NativeWindowHandle HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Host: 127.0.0.1:4723
HTTP/1.1 200 OK
Content-Length: 81
Content-Type: application/json
{"sessionId":"sessionId","status":0,"value":"1234567"}
==========================================
POST /session HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Content-Length: 79
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
{"desiredCapabilities":{"appTopLevelWindow":"12345A","platformName":"Windows"}}
HTTP/1.1 200 OK
Content-Length: 127
Content-Type: application/json
{"sessionId":"sessionId","status":0,"value":{"appTopLevelWindow":"12345A","platformName":"Windows"}}
call: desktopsession.FindElementByName("AppName") -> this gives some random results while we trigger the scripts through command prompt
call: var appwindows = desktopsession.FindElementsByClassName("Window);
var test =appwindows .Where(w => w.Text.Equals("App name")).FirstOrDefault();
I am not understanding why this is not happening through commands given outside the VS's environment
I tried even waiting for sometime to identify the elements buts its not happening.
If someone has any clue regarding this, please help
Note: I tried setting the environment variables as well, it did not help
The text was updated successfully, but these errors were encountered: