Python3.x: "Cannot connect to the Service (driver)"

1,759 views
Skip to first unread message

Luuk Looijenga

unread,
Jun 19, 2019, 12:36:21 AM6/19/19
to Selenium Users
OS: macOS Mojave, version 10.14

Selenium version: selenium-3.141.0

Browser: Chrome/Firefox


Hi there, 

I'm having troubles getting my selenium to work in python 3.x. At first everything was working as supposed to. When I tried to use it a couple of hours later it would not work anymore. I'm using the following code (from the repository):

import unittest
from selenium import webdriver

class GoogleTestCase(unittest.TestCase):

def setUp(self):
self.browser = webdriver.Firefox()
self.addCleanup(self.browser.quit)

def testPageTitle(self):
self.browser.get('http://www.google.com')
self.assertIn('Google', self.browser.title)

if __name__ == '__main__':
unittest.main(verbosity=2)

and I'm getting the following message:

======================================================================
ERROR: testPageTitle (__main__.GoogleTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test.py", line 7, in setUp
    self.browser = webdriver.Firefox()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
    self.service.start()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 104, in start
    raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service geckodriver

----------------------------------------------------------------------
Ran 1 test in 30.168s

FAILED (errors=1)


I have tried it with the chromedriver as well, and it makes no difference. 
The things I have tried so far:
- reinstall selenium
- move drivers to /usr/local/bin
- check /etc/hosts/ for 127.0.0.1. localhost
- using the same driver version as browser version (for chrome at least).

I wasn't able to find any possible solutions online, and none of these have worked for me. Does anyone know what I can do? 
Thanks in advance.

Luuk Looijenga

unread,
Jun 19, 2019, 5:01:40 AM6/19/19
to Selenium Users

Update: it seems like it has something to do with the network I'm on. I'm back to the original network that I set Selenium up with, and now everything works fine. The problem is, that I set everything up in the library and I would like to use it at home. 
Reply all
Reply to author
Forward
0 new messages