0

When I try to execute this code :

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver= webdriver.Firefox("C:\Program Files\Mozilla Firefox")
driver.get("http://google.com")

I get the following error :

C:\Users\vipul\PycharmProjects\newproject\venv\Scripts\python.exe "C:/Users/vipul/PycharmProjects/newproject/Web Scraping.py"
Traceback (most recent call last):
  File "C:\Users\vipul\PycharmProjects\newproject\venv\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Users\vipul\AppData\Local\Programs\Python\Python36-32\Lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Users\vipul\AppData\Local\Programs\Python\Python36-32\Lib\subprocess.py", line 997, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/vipul/PycharmProjects/newproject/Web Scraping.py", line 4, in <module>
    driver= webdriver.Firefox("C:\Program Files\Mozilla Firefox")
  File "C:\Users\vipul\PycharmProjects\newproject\venv\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 148, in __init__
    self.service.start()
  File "C:\Users\vipul\PycharmProjects\newproject\venv\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

Process finished with exit code 1
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Vipul Rodrigues
  • 127
  • 1
  • 1
  • 7
  • Push your code trials. – Ratmir Asanov Dec 22 '17 at 08:54
  • Possible duplicate of [chrome headless browswer selenium python](https://stackoverflow.com/questions/46085270/chrome-headless-browswer-selenium-python/46089751#46089751) – undetected Selenium Dec 22 '17 at 09:24
  • 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) – Saurabh Gaur Dec 22 '17 at 09:47

2 Answers2

0

I have faced the same issue before a week ago, I was using Python 2.7 and the latest version of web driver of Chrome, Then I passed geckodriver file path like,

driver= webdriver.Firefox("c://your-path")

This fixed my issue, I hoped for your too.

Prabhakar
  • 1,138
  • 2
  • 14
  • 30
Sachin Raghav
  • 452
  • 5
  • 14
0

Download geckodriver.exe to a particular folder/directory(eg. c:\drivers) then set the driver path.

Try any one of the following ways.

  1. Pass driver path as argument.

    driver= webdriver.Firefox("c:\drivers\geckodriver.exe")
    driver.get("http://google.com")
    
  2. Set driver path using enviornment.

    import os
    os.environ['webdriver.gecko.driver'] ="c:\drivers\geckodriver.exe"
    driver.get("http://google.com")
    

Note: if you are keeping gecko driver exe file in local folder where the script is there. then no need to set or pass the driver path.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Murthi
  • 5,299
  • 1
  • 10
  • 15