WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

HTTP/1.1 404 Not Found WinAppDriver unable to connect to App using AppID

Open Urvika-gola opened this issue 3 years ago • 12 comments

Hi! I am trying to connect play around with Calculator's UI using Winappdriver in Python. My simple python code is :-

from appium import webdriver
desired_caps = {}
desired_caps["platformName"] = "Windows"
desired_caps["app"] = "Microsoft.WindowsCalculator_8..some_characters..!App"
desired_caps["deviceName"] = "WindowsPC"
#desired_caps["newCommandTimeout"] = 60
driver = webdriver.Remote("http://127.0.0.1:4723/", desired_caps)

I am starting WinAppDriver.exe and it starts successfully:

C:\Program Files\Windows Application Driver>WinAppDriver.exe
Windows Application Driver listening for requests at: http://127.0.0.1:4723/
Press ENTER to exit.

But it doesn't work and throws this error :- Python throws selenium.common.exceptions.WebDriverException with no message and WinAppDriver shows

POST //session/ HTTP/1.1
Accept: application/json
Accept-Encoding: identity
Content-Length: 352
Content-Type: application/json;charset=UTF-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (python windows)

{"capabilities": {"firstMatch": [{"platformName": "Windows", "appium:app": "Microsoft.WindowsCalculator_8..some_characters..!App", "appium:deviceName": "WindowsPC", "appium:newCommandTimeout": 60}]}, "desiredCapabilities": {"platformName": "Windows", "app": "Microsoft.WindowsCalculator_88..some_characters..!App", "deviceName": "WindowsPC", "newCommandTimeout": 60}}
**HTTP/1.1 404 Not Found**

I have tried with few other app ids or direct path to the exe instead of the app id, nothing seems to be working. It's the first step towards using find_element_by_name calls but I am not able to proceed further due to this error. Could someone please help?

Installed Win App Driver :-https://github.com/Microsoft/WinAppDriver/releases Installed pip install Appium-Python-Client Installed Windows SDK Python Version 3+ Developer Mode is enabled,

Urvika-gola avatar Sep 24 '21 10:09 Urvika-gola

Hi @Urvika-gola I think, the app id is incorrect. It should be something like- Microsoft.WindowsCalculator_8wekyb3d8bbwe!App

I would suggest using Appium to control winappdriver. Steps to configure:

  1. Install appium from admin terminal: npm i -g [email protected]
  2. Start appium with command: appium
  3. Update your create session command to: driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)

Please give it a try and let me know how it goes

shoaibmansoor avatar Sep 24 '21 21:09 shoaibmansoor

I'm also facing this error . How can I solve this??

sandhiyasivakumar1610 avatar Jul 09 '22 06:07 sandhiyasivakumar1610

@Urvika-gola Were you able to resolve this issue. I am also having the same setup, getting the same issue and I am stuck on this. As @shoaibmansoor said, I even tried giving the correct id Microsoft.WindowsCalculator_8wekyb3d8bbwe!App still no luck. I always see the same issue

========================================== POST //session/ HTTP/1.1 Accept: application/json Accept-Encoding: identity Connection: keep-alive Content-Length: 250 Content-Type: application/json;charset=UTF-8 Host: 127.0.0.1:4723 User-Agent: appium/python 1.3.0 (selenium/3.141.0 (python windows)) X-Idempotency-Key: d3b419d2-7859-474a-8086-d76c8cdcc7a3

{"capabilities": {"firstMatch": [{"appium:app": "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App", "ms:experimental-webdriver": true}]}, "desiredCapabilities": {"app": "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App", "ms:experimental-webdriver": true}} HTTP/1.1 404 Not Found

manju1847 avatar Mar 28 '23 20:03 manju1847

Yes, I had just written out a forged App ID, desired_caps["app"] = "Microsoft.WindowsCalculator_8..some_characters..!App" Although, I was using the correct App ID. @manju1847 I remember, that sometimes when I toggle the resize of the calculator window (maximize to minimize or vice versa), it worked.

Urvika-gola avatar Mar 28 '23 21:03 Urvika-gola

@Urvika-gola Glad to see your response. Yes. I tried with that too. desired_caps["app"] = "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App". Still no luck. Do we need to install Appium server by any chance? Currently in my setup I have installed these

  1. winAppDriver
  2. Appium-Python-client
  3. Enabled developer mode
  4. Using Python 3.7 (32 bit)

Even I tried with other application. But winAppDriver response is same - HTTP/1.1 404 Not Found

manju1847 avatar Mar 28 '23 21:03 manju1847

Here's some Python code I have to launch Calculator. Note that you shouldn't be launching Appium itself when using the appium library with WinAppDriver. Ignore the _call()... that just launches WinAppDriver on the remote device.

` from appium import webdriver

Tutorial for creating a scenario:

- Launch Calculator and exit

class Calc(scenarios.app_scenario.Scenario):

def setUp(self):
    # Start WinAppDriver server
    self._call([(self.dut_exec_path + "\\WindowsApplicationDriver\\WinAppDriver.exe"), (self.dut_resolved_ip + " " + self.app_port + " /forcequit")], blocking=False)
    time.sleep(1)
    desired_caps = {}
    desired_caps["app"] = "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"
    desired_caps["ms:experimental-webdriver"] = True
    dut_url = "http://" + self.dut_resolved_ip + ":" + self.app_port
    self.driver = webdriver.Remote(command_executor = dut_url, desired_capabilities = desired_caps)

`

jewilder avatar Mar 28 '23 22:03 jewilder

Yes. I am only starting WinAppDriver manually on local machine. I have windows calculator up and running. I have installed python Appium-Python-client package and enabled developer mode on my Windows 10.

Here is my code

    desired_caps = {}
    desired_caps["app"] = "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"
    desired_caps["ms:experimental-webdriver"] = True        
    desired_caps["platformName"] = "Windows"
    desired_caps["deviceName"] = "WindowsPC"
    driver = webdriver.Remote("http://127.0.0.1:4723/", desired_capabilities=desired_caps)

This is the response getting from WinAppDriver

POST //session/ HTTP/1.1 Accept: application/json Accept-Encoding: identity Connection: keep-alive Content-Length: 365 Content-Type: application/json;charset=UTF-8 Host: 127.0.0.1:4723 User-Agent: appium/python 1.3.0 (selenium/3.141.0 (python windows)) X-Idempotency-Key: e6348d23-f4a0-4fb0-aba9-da776916dccb

{"capabilities": {"firstMatch": [{"appium:app": "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App", "ms:experimental-webdriver": true, "platformName": "Windows", "appium:deviceName": "WindowsPC"}]}, "desiredCapabilities": {"app": "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App", "ms:experimental-webdriver": true, "platformName": "Windows", "deviceName": "WindowsPC"}} HTTP/1.1 404 Not Found

manju1847 avatar Mar 28 '23 22:03 manju1847

Try opening port 4723 in your firewall:

netsh.exe advfirewall firewall add rule name="Allow 4723,17556" dir=in action=allow enable=yes localport=4723,17556 protocol=TCP profile=public,private,domain

jewilder avatar Mar 28 '23 22:03 jewilder

@jewilder: I tried the command that you shared. Still the result is same - HTTP/1.1 404 Not Found

After some hit and try, I found issue is because of extra forward slash in the input URL.

webdriver.Remote("http://127.0.0.1:4723/", desired_capabilities=desired_caps) ==> This will throw 404 Not Found

webdriver.Remote("http://127.0.0.1:4723", desired_capabilities=desired_caps) ==> This works perfectly.

May be this is the issue even for @Urvika-gola, because I can see even she has extra forward slash in her input URL.

manju1847 avatar Mar 29 '23 15:03 manju1847

Does anyone faced following issue? {"status":100,"value":{"error":"invalid argument","message":"Bad capabilities. Specify either app or appTopLevelWindow to create a session"}}

SrLeet03 avatar Aug 03 '23 06:08 SrLeet03

Yes i'm facing the same issue and i don't know how to figure this one out

Arcod7 avatar Sep 18 '23 14:09 Arcod7

I am also facing same issue "Bad capabilities. Specify either app or appTopLevelWindow to create a session", any solution?

hritha avatar Sep 21 '23 18:09 hritha