Reputation:
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()
Upvotes: 2
Views: 1103
Reputation: 193058
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()))
Upvotes: 2