Reputation: 65
My code (from eg here https://pypi.org/project/selenium/)
from selenium import webdriver**
browser = webdriver.Firefox()
Error
Traceback (most recent call last):
File "C:\Users\saltlake\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\saltlake\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\saltlake\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:\Project\python-work\website.py", line 3, in <module>
browser = webdriver.Firefox()
File "C:\Users\saltlake\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
self.service.start()
File "C:\Users\saltlake\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' executable needs to be in PATH.
Anybody aware this problem/fix?
Upvotes: 1
Views: 2571
Reputation: 21
The error here is for the unavailability of a firefox web driver to work with.
There are 2 ways you can have the driver,
Go to this website Firefox web driver for python, and download the latest version of the web driver, but that'll help you run the code on your locale only, everytime you run code on another machine it'll ask for rewriting the path you'll give for web driver. If you haven't included the .exe file in the project folder.
The better approach is to get familiarize with the webdriver manager python, which makes your code more portable and robust, which helps you set up the driver you need automatically. This approach will help you write efficient codes at the beginning itself.
Upvotes: 0
Reputation: 459
You're getting this error because you don't have selenium web driver for firefox.
To get it, go to the website https://github.com/mozilla/geckodriver/releases
Download the version suitable for your os.
Extract it
Place the extracted file in the same directory you're running this script.
I.e your "website.py" file must be in the same directory as the extracted file
Viola!!!
Upvotes: 1