I've been working on a project for a while now. Only recently, for whatever reason I started getting an error:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
This is strange because I already have chromedriver in PATH. I've also had chromedriver in the same folder as the project I've been working on. I've also gone to the extent to create a test file named moo.py. It's very basic with the intent of testing the chromedriver. The code is as follows:
from selenium.webdriver.chrome.options import Options
from time import sleep
from selenium import webdriver
options = Options()
options.binary_location = 'C:\Program Files\Google\Chrome\Application\chrome.exe'
driver = webdriver.Chrome(executable_path=r'C:\webdrivers\chromedriver.exe', chrome_options = options)
driver.get('https://www.google.com')
print('Chrome opened')
time.sleep(5)
driver.quit()
Even when running this, it still gives me the same error. I'm not really sure what to do now since I've tried fixing this the several various ways I know how. I'd appreciate any and all feedback. Kind regards.
edit 1: Chromedriver is actively working in PATH.
C:>chromedriver Starting ChromeDriver 92.0.4515.107 (87a818b10553a07434ea9e2b6dccf3cbe7895134-refs/branch-heads/4515@{#1634}) on port 9515 Only local connections are allowed. Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe. ChromeDriver was started successfully.
That's the response when I type chromedriver into cmd with C:\ as the cd.
Some additional information, I'm on Windows 10, laptop. Chromedriver was working fine before, then just seemingly stopped out of nowhere.
from selenium.webdriver.chrome.options import Options
from time import sleep
from selenium import webdriver
# options = Options()
# options.binary_location = 'C:\Program Files\Google\Chrome\Application\chrome.exe'
# driver = webdriver.Chrome(executable_path=r'C:\webdrivers\chromedriver.exe', chrome_options = options)
driver = webdriver.Chrome()
driver.get('https://www.google.com')
print('Chrome opened')
time.sleep(5)
driver.quit()
I then tried to comment out the part about finding chrome, made sure I had the right version of chromedriver in the same folder as moo.py, changed the code to the above, and still get the same error.
After that, I removed the chromedriver from the folder with moo.py, insinuating that it would just get the info from PATH, and it again, throws the same error.
And here is the entire traceback error I get. Same error every time.
C:\webdrivers>python moo.py Traceback (most recent call last): File "C:\Users\Sean\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start self.process = subprocess.Popen(cmd, env=self.env, File "C:\Users\Sean\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 829, in init errread, errwrite) = self._get_handles(stdin, stdout, stderr) File "C:\Users\Sean\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1279, in _get_handles c2pwrite = msvcrt.get_osfhandle(self._get_devnull()) File "C:\Users\Sean\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1062, in _get_devnull self._devnull = os.open(os.devnull, os.O_RDWR) FileNotFoundError: [Errno 2] No such file or directory: 'nul'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\webdrivers\moo.py", line 22, in driver = webdriver.Chrome() File "C:\Users\Sean\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in init self.service.start() File "C:\Users\Sean\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start raise WebDriverException( selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home