0

I've looked at several other forum posts and found similar problems, but after trying all the solutions none of them have worked thus far. Here is my code (taken directly from a tutorial I've been following):

from time import sleep
from selenium import webdriver
driver = webdriver.Firefox(executable_path='/opt/geckoDriver/geckodriver.exe')
driver.get('https://instagram.com/')
sleep(5)
driver.close()

And here is the error it's spitting out:

Traceback (most recent call last):
  File "C:\Users\14053\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\14053\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\14053\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
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 "D:\Documents\Python\Instagram bot 0.py", line 5, in <module>
    driver = webdriver.Firefox(executable_path='/opt/geckoDriver/geckodriver.exe')
  File "C:\Users\14053\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
    self.service.start()
  File "C:\Users\14053\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'geckodriver.exe' executable needs to be in PATH. 

I've downloaded the geckodriver executable but it's just in my downloads folder because I have no clue where to put it for the code to access it. I've tried a few places but haven't had much luck.

(I'm somewhat new to programming/indexing in general, so explain it to me like I'm a student who has no clue)

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • you should specify where the geckodriver.exe file is in the executable_path instead of using what you have there. – ewokx Jul 15 '20 at 03:56

1 Answers1

0

Right now, the code uses a path that refers to nothing. That's why you're getting the FileNotFound error. Instead of executable_path='/opt/geckoDriver/geckodriver.exe', you should change the executable_path to the path of your geckoDriver executable. So, it would be like (but isn't) C:\\Users\\Downloads\\geckoDriver.exe. You should also make sure that the backslashes are escaped, or else you will get another FileNotFound error since it will try to escape the character after it.

Axiumin_
  • 2,107
  • 2
  • 15
  • 24