Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Selenium starts the browser but shows an error as Message: Can not connect to the Service

The code starts the browser, stops at this step (line 5), and after a while throws an error:

selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service C:\Program Files\Mozilla Firefox\firefox.exe

from selenium import webdriver
from selenium.webdriver.firefox.service import Service

s = Service(r'C:\Program Files\Mozilla Firefox\firefox.exe')
driver = webdriver.Firefox(service=s)
driver.get('http://www.google.com')
myPageTitle = driver.title
print(myPageTitle)
driver.quit()

Firefox – 95.0.2
Selenium – 4.1.0

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried with chrome, same problem

Does anyone know what the problem is and how to solve it?

>Solution :

As an argument to Service() instead of the executable, you need to pass the absolute location of the GeckoDriver executable which can be downloaded from mozilla/geckodriver page.

So your effective code block will be:

from selenium import webdriver
from selenium.webdriver.firefox.service import Service

s = Service(r'C:\path\to\geckodriver.exe')
driver = webdriver.Firefox(service=s)
driver.get('http://www.google.com')
myPageTitle = driver.title
print(myPageTitle)
driver.quit()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading