0

I've trawled the web and SO for a good few hours and have exhausted all solutions I can find. Windows 10 / Chrome 87.0 / Python 3.

from selenium import webdriver

DRIVER_PATH = r'./chromedriver/chromedriver.exe'
driver = webdriver.Chrome(executable_path=DRIVER_PATH)

returns:

WebDriverException: Message: Can not connect to the Service ./chromedriver/chromedriver.exe
  • I have made sure that the chromedriver is added to path

    enter image description here

  • I have added 127.0.0.1 localhost to a clean hosts file in %windir%\System32\drivers\etc

    enter image description here

  • I have tried specifying the driver path explicitly and implicitly

halfer
  • 19,824
  • 17
  • 99
  • 186
roastbeeef
  • 1,039
  • 1
  • 12
  • 23

2 Answers2

0

You need to insert the entire path, on windows its like this:

executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe'
Timeler
  • 377
  • 1
  • 11
  • if i used the full windows path i just get a permissions error `executable may have wrong permissions` – roastbeeef Dec 03 '20 at 13:11
  • are you admin on your computer? – Timeler Dec 03 '20 at 13:16
  • yep, i am using the admin account – roastbeeef Dec 03 '20 at 13:18
  • thats pretty strange, the error you currently get refers to the fact that you did not insert the full path, so that would technically be the solution i think – Timeler Dec 03 '20 at 13:19
  • which error, the cannot connect to the service? i always thought that that assumed that the webdriver was found (just by the behaviour - the error takes a few seconds to produce rather than insufficient permissions, or any of the other errors infact, which are instant) – roastbeeef Dec 03 '20 at 13:26
  • hmm, that might also be – Timeler Dec 03 '20 at 13:28
0

This os path...

r'./chromedriver/chromedriver.exe'

...refers to the ChromeDriver executable within the chromedriver sub-directory which is located in the same directory from where your program executes.

By all possible means r'./chromedriver/chromedriver.exe' is not the actual location of the ChromeDriver executable within your system. Hence you see the error.


Solution

Pass the absolute path of the ChromeDriver as follows:

from selenium import webdriver

DRIVER_PATH = r'C:\..\..\chromedriver\chromedriver.exe'
driver = webdriver.Chrome(executable_path=DRIVER_PATH)

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • hi. as mentioned, i have tried the absolute path by using something like this: `full_windows_path = r"c:\webdrivers\chromedriver.exe" driver = webdriver.Chrome(executable_path=full_windows_path)` where i just get an access denied error. i've also tried all solutions in the first of the post you have linked, but havent yet read the second and third (will do now) – roastbeeef Dec 03 '20 at 13:37
  • @roastbeeef carefully go through the points mentioned in the _Mandatory Considerations_ sections. I'm sure you will be through. – undetected Selenium Dec 03 '20 at 13:41