1

I can't understand why geckodriver doesn't work and why the path doesn't exist. I use Ubuntu and Firefox, I uninstalled and reinstalled geckodriver and Firefox-geckodriver. I checked the version and I use geckodriver 0.30.0 (d372710b98a6 2021-09-16 10:29 +0300). I have already tried uninstalling and installing with

wget https://github.com/mozilla/geckodriver/releases/download/v0.30.0/geckodriver-v0.30.0-linux64.tar.gz
tar -xvzf geckodriver-v0.30.0- linux64.tar.gz 
chmod + x geckodriver 
export PATH = $ PATH: / path-to-extracted-file /

I also installed

sudo apt install firefox-geckodriver

I try to run this little script, but I get the error:

raise WebDriverException (
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

Code

from selenium.webdriver import Firefox
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver

from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
import os

from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
profile_path = '/home/jack/.local/share/torbrowser/tbb/x86_64/tor-browser_en-US/Browser/TorBrowser/Data/Browser/profile.default'

options=Options()
options.set_preference('profile', profile_path)
options.set_preference('network.proxy.type', 1)
options.set_preference('network.proxy.socks', '127.0.0.1')
options.set_preference('network.proxy.socks_port', 9050)
options.set_preference("network.proxy.socks_remote_dns", False)

service = Service('/usr/bin/geckodriver')
driver = Firefox(service=service, options=options)

driver.get("www.google.com")
driver.quit()
furas
  • 134,197
  • 12
  • 106
  • 148
  • in `PATH` it has to be path to folder with `geckodriver` - `/usr/bin`, not path to file `geckodriver` - `/usr/bin/geckodriver`. I have on `PATH` folder in my home `/home/furas/bin` and in this folder I put all needed programs or scripts (in Python, Perl, Ruby, etc) – furas Apr 01 '22 at 06:20
  • you may have to add to `PATH` in `.bashrc` so it would set it everytime when you restart computer – furas Apr 01 '22 at 06:28
  • I have `geckodriver` in folder `/home/furas/bin/` and when I use `Service('/home/furas/bin/geckodriver')` then it works. Maybe you don't have `geckodriver` in folder `/usr/bin/` but in different folder - maybe full path is `/usr/bin/geckodriver/geckodriver` or maybe you put file in home folder. You should first check if you can run `/usr/bin/geckodriver --version` in console/terminal to see version. – furas Apr 01 '22 at 06:30
  • see also module [webdriver_manager](https://github.com/SergeyPirogov/webdriver_manager) which can check if you have correct driver and download it. – furas Apr 01 '22 at 06:36

1 Answers1

1

There seems to be some ambiguity about the path/location where GeckoDriver is getting downloaded which may not be in PATH / deafault location.

In such cases as @furas suggested the easiest way out is to use the Webdriver Manager.

Sample code:

  • Selenium 3 compatible code:

    from selenium import webdriver
    from webdriver_manager.firefox import GeckoDriverManager
    
    driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
    
  • Selenium 4 compatible code:

    from selenium import webdriver
    from selenium.webdriver.firefox.service import Service
    from webdriver_manager.firefox import GeckoDriverManager
    
    driver = webdriver.Firefox(service=Service(GeckoDriverManager().install()))
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352