0

How can I install firefox web driver to work with selenium\python

I installed it with the command

pip install selenium

I tried this code:

driver=webdriver.Firefox()
driver.get("https://www.google.com")
content=driver.find_element_by_id("lga")
print(content)

But it gives me this error

Traceback (most recent call last):
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python37-32\lib\site-package
s\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python37-32\lib\subprocess.p
y", line 775, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python37-32\lib\subprocess.p
y", line 1178, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".\Class.py", line 3, in <module>
    class Scrape:
  File ".\Class.py", line 4, in Scrape
    driver = webdriver.Firefox()
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python37-32\lib\site-package
s\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
    self.service.start()
  File "C:\Users\Acer\AppData\Local\Programs\Python\Python37-32\lib\site-package
s\selenium\webdriver\common\service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable
 needs to be in PATH.
ali filali
  • 310
  • 4
  • 8
  • 3
    Possible duplicate of [Selenium using Python - Geckodriver executable needs to be in PATH](https://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path) – orde Oct 20 '19 at 04:28

1 Answers1

1

A few things to check out.

1) you need to make sure you have install Firefox.
2) Get the latest gecko driver here
3) Set path in your environment

export PATH=$PATH:/path/to/directory/of/executable/geckodriver<br>

4) If you intend to skip 3 , you need to amend this in the your script

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('C:\Firefox\Firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)
john
  • 413
  • 7
  • 16
  • 1
    It didn't work for me even that I did the webdriver to the path in the enviroment but this line of code solved it : driver = webdriver.Firefox(executable_path=r'C:\webdriver\geckodriver.exe') anyway thank you for your help – ali filali Nov 05 '19 at 18:25
  • Maybe I don't understand what's going on, but I'm a little confused on needing geckodriver to be in PATH, but manually setting the path to the firefox binary in python? Should that be making python aware of the geckodriver, not Firefox itself? – Hendy Jun 29 '22 at 18:43