0

I am trying to a basic python script for connecting to a web browser using the selenium package. The error log as shown is posted below.

Traceback (most recent call last):
  File "F:\WinPython\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "F:\WinPython\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "F:\WinPython\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\subprocess.py", line 1224, 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 "F:/WinPython/WinPython-64bit-3.5.2.3Qt5/python-3.5.2.amd64/py_codes/python_org_search.py", line 4, in <module>
    driver = webdriver.Firefox()
  File "F:\WinPython\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 140, in __init__
    self.service.start()
  File "F:\WinPython\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\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. 
HelpMePlz
  • 51
  • 7
Anjishnu
  • 1
  • 2
  • Exception log is not enough to understand the problem. Show your code also – Andersson Dec 06 '16 at 14:22
  • Duplicate of http://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path which already has the answer – CJC Dec 06 '16 at 14:24
  • @Andersson here is the code from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox() driver.get("http://www.python.org") assert "Python" in driver.title elem = driver.find_element_by_name("q") elem.clear() elem.send_keys("pycon") elem.send_keys(Keys.RETURN) assert "No results found." not in driver.page_source driver.close() – Anjishnu Dec 06 '16 at 14:34

1 Answers1

0

From selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH., it is clear that you need to add geckodriver to your system path, more specifically the folder that contains geckodriver.exe should be added to the system path.

To do that, run cmd.exe as an administrator and run the following command:

setx path "%path%;C:\Path\to\geckodriver.exe\;"

Replace C:\Path\to\geckodriver.exe\ with your exact path to the folder that contains geckodriver.exe

Edit:

You can download the exe file from here https://github.com/mozilla/geckodriver/releases, extract it somewhere, let's say C:\geckodriver. Now, you have your file like this C:\geckodriver\geckodriver.exe and you need to add C:\geckodriver to your system path. And, run your script in a new console.

ettanany
  • 19,038
  • 9
  • 47
  • 63
  • there is no geckodriver.exe all i found was a txt file named geckodriver which was generated in the same folder in which the python file containing the code was situated @ettanany – Anjishnu Dec 06 '16 at 14:37
  • Take a look at my edited answer, if you did not download and extract the exe file before, then you will need to do that by following the link above. – ettanany Dec 06 '16 at 14:47