Selenium python: Can not connect to the Service %s" % self.path
Asked Answered
D

4

7

I am trying to run a selenium test with python script, but I am receiving the following error when executing the test:

Traceback (most recent call last):
File "/var/www/html/selenium-scripts/example.py", line 13, in <module>
driver = webdriver.Chrome()
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 61, in __init__self.service.start()
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 88, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver

Please advice how to resolve this

Delfinadelfine answered 25/2, 2016 at 10:29 Comment(5)
Please look at this solution: #35625189Populace
You are linking to my question?Delfinadelfine
Sorry, wrong link ;) There is a solution: #24901422Populace
Is it solved? because I have the same problemPenelopa
Can someone solve this. I have same issue on Mac OS XCultivar
E
7

After googling for a while, and trying various solutions. I found the one that worked for me at here: https://github.com/SeleniumHQ/selenium/issues/2903#issuecomment-272112510

As mentioned in that comment, try to add 127.0.0.1 localhost to /etc/hosts

Ens answered 26/8, 2017 at 5:45 Comment(0)
L
2

For MAC System: Change the host file to default as below: 1. Command+Shift+G go to /private/etc/hosts 2.Open in Text File 3. File > Save as and uncheck the box for “If no extension is provided use txt” and rename hosts 4.Go Terminal execute command cat /etc/hosts Check if it shows

##
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
Lair answered 12/4, 2018 at 3:3 Comment(1)
You should provide everything necessary in the answer itself, not just part of it. In other words, answers should be self-contained.Mesognathous
T
1

For windows C:\Windows\System32\drivers\etc\hosts

Open as Administrator a Notepad then open the file hosts and do all the changes you need, in my particular case was:

0.0.0.0            localhost

to:

127.0.0.1 localhost

that fixed my problem with Selenium.

Tree answered 22/1, 2020 at 19:18 Comment(0)
M
0
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

driver = webdriver.Chrome(service=Service(executable_path="..../chrome/chrome"))
driver.get('https://www.instagram.com/')

Make sure you have downloaded the correct driver file. I made the mistake of downloading chrome name file, not the chromedriver. 1

Matriculation answered 5/8, 2024 at 14:24 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.