question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hostname invalid error when running on localhost as non-admin

See original GitHub issue

I am trying to automate starting winappdriver.exe by spawning a background process from Ruby in my Cucumber script. No problem with spawn, as I have tested using it with other commands.

  • The first problem is that I have to run winappdriver.exe as administrator. I looked into runas.exe but that still requires input, so it’s bad for scripting. There are other reasons not to chase this.
  • The alternative is to use “localhost” as the host, since winappdriver.exe tells me I can run only as localhost without admin privileges.

winappdriver.exe localhost 4723/wd/hub

However, when I try to create the Appium webdriver, I get the following error:

  unexpected response, code=400, content-type="text/html"
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
  <HTML><HEAD><TITLE>Bad Request</TITLE>
  <META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
  <BODY><h2>Bad Request - Invalid Hostname</h2>
  <hr><p>HTTP Error 400. The request hostname is invalid.</p>
  </BODY></HTML> (Selenium::WebDriver::Error::WebDriverError)

Now if I just start winappdriver manually as administrator using 127.0.0.1 it works fine…

winappdriver.exe 127.0.0.1 4723/wd/hub

…but the problem is that it’s not great for fully automating my tests (starting and stopping winappdriver between my Cucumber runs would be nice, instead of the choice of either manual or always on).

Seeing that localhost and 127.0.0.1 are essentially the same, I did not expect an error when using one but not the other.

Thanks.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
inel85commented, Jan 4, 2018

Hi jsbakker,

I’m also confirming the need to start winappdriver as an admin and the issues you described starting with the 2nd run. I’m using the same version 1.0.1708.10001.

To your error when using hostname instead of the IP => I encountered the same issue in the beginning, unfortunately I can’t remember exactly what fixed it, but I managed to overcome it, I’m now able to start winappdriver with ‘localhost’ or even <hostname> if I use it remotely winappdriver.exe localhost 4723

Some useful tips:

  • Be consistent: if you start WinAppDriver with IP, be sure to use the IP as well when initializing the WindowsDriver, in the test project. And viceversa, if you use hostname when starting WinAppDriver, use the hostname as well during driver initialization.
  • I gave up of using /wd/hub in winappdriver.exe localhost 4723/wd/hub, as an initial workaround for some errors, perhaps exactly for the hostname error. It works just fine for me without the /wd/hub

Question: Did you manage to find a solution for starting and stopping winappdriver between your tests run? It ys, it would be helpful if you post it here, I’m also searching a way.

0reactions
vagisha-nidhi195commented, Mar 24, 2022

@hassanuz I am able to start a session without admin mode with 127.0.0.1 but I am not able to remotely connect to it. I can connect properly when I use the ip address, but unfortunately, using IP needs elevated admin permissions. If I am running in a CI/CD env, I will not be able to get elevated permissions. How do we bypass this?

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hostname invalid error when running on localhost as non- ...
I am trying to automate starting winappdriver.exe by spawning a background process from Ruby in my Cucumber script. No problem with spawn, ...
Read more >
Bad Request- Invalid Hostname while connect to localhost ...
I get the Bad Request- Invalid Hostname [HTTP ERROR 400] while trying connect my laptop's localhost. Actually, I am learning to develop mobile ......
Read more >
All invalid hostnames resolve to localhost in my browser. ...
1 Answer 1 · Open your local network adapter settings, and change your IPv4 and / or IPv6 DNS settings from "Obtain DNS...
Read more >
Localhost vs 127.0.0.1 - Error when referring to own IP ...
1 Answer. After playing around for some time, I think I figured it out. The service I was running was on visual studio's...
Read more >
Enable PowerShell Remoting on a standalone (workgroup) ...
To run this cmdlet, start Windows PowerShell with the "Run as administrator" option. ... winrm : Error: Invalid use of command line…
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found