0
imports...
browser = webdriver.Firefox()
browser.get('http://google.com')

I'm trying to execute the code above. It used to work and now it doesn't: Firefox doesn't even open. The code, Python, Selenium and all the other libraries, Firefox and geckodriver have not changed at all since when it worked. What changed was that I installed many new apps in my Windows PC, such as: Plex media server, Eclipse, Java development kit and many Java libraries, Maven, Postgresql and Git.

Here's all that appears in the terminal when I run:

    Traceback (most recent call last):
  File "C:\Users\hougy\OneDrive\Documentos\plij\seleniumtest.py", line 26, in <module>
    browser = webdriver.Firefox()
  File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 175, in __init__
    self.service.start()
  File "C:\Users\hougy\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 108, 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

When it was working, the message "1636932662336 geckodriver INFO Listening on 127.0.0.1:49684" appeared in the geckodriver.log, followed by a lot of stuff. Now, only that message appears. Each time, the code before "geckodriver INFO" and the port are different.

I was thinking that maybe the problem was that they all try to use localhost. So I made sure Plex and Postgre were not running. I also tried a solution that wanted you to make sure 127.0.0.1 was mapped to localhost in a Windows file.

I also tried many of the common selenium solution such adding some options, making sure the geckodriver is found and updating everything.

If I run the same code in another PC that's also in my home, it works perfectly, but I need to make it work in this PC.

It's been more than a year since I need to use Selenium and I was working with Chrome and chromedriver before, but I had problems and had to waste a lot of time debugging all the time, probably because Chrome update frequently. So recently, when I couldn't solve the latest problem, I found out I could use Firefox just for this and configure it to never update. I thought my pain was over, but here I am again. Here's the problem I couldn't fix last time with chromedriver:

Selenium Python code that used to work now opens browser and then gets stuck in "data:,". Says "chrome not reachable"

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Hougy
  • 43
  • 8

1 Answers1

0

This error message...

selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service geckodriver

...implies that your program is unable to start the GeckoDriver Service.

Solution

Use the key executable_path to point to the downloaded matching version of the GeckoDriver as follows:

browser = webdriver.Firefox(executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
browser.get('http://google.com')

However, your main issue seem to be the incompatibility between the version of the binaries you are using.

Solution

Ensure that:

  • GeckoDriver is updated to current GeckoDriver v0.30.0 level.
  • Firefox is updated to current Firefox Version 94.0.1 level. (as per mapping between geckodriver releases, and required versions of Selenium and Firefox).
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your @Test as non-root user.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • You're the same person that was kind enough to answer my other question about chromedriver. Unfortunately, it didn't solve my problem then and it doesn't solve my problem now. This question description even says that I already tried your solution. My other PC has the exact same python, selenium and other libraries, firefox, geckodriver and script versions, synced with onedrive, and it works there. I think problem is indeed the new software I installed. So far I am unable to use both geckodriver and chromedriver due to different problems. – Hougy Nov 16 '21 at 02:34