Home > Back-end >  Message: 'chromedriver.exe' executable needs to be in PATH
Message: 'chromedriver.exe' executable needs to be in PATH

Time:10-12

I have made a program that was working just fine until one day it randomly started giving me this error: Message: 'chromedriver.exe' executable needs to be in PATH. even though the "chromedriver" is in a path. I used this code:

CHROME_PATH ='C:\Program Files\Google\Chrome\Application\chrome.exe'
CHROMEDRIVER_PATH = 'C:\Users\Sahar\Desktop\bot\chromedriver.exe'
WINDOW_SIZE = "1920,1080"
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--window-size=%s" % WINDOW_SIZE)
chrome_options.binary_location = CHROME_PATH
 

browser=webdriver.Chrome(executable_path='chromedriver.exe',chrome_options=chrome_options)

this code is being ran in a exe file made using pyinstaller

CodePudding user response:

Instead of executable_path='chromedriver.exe' try using the new approach service=webdriver_service as following:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("--headless")
options.add_argument("--window-size=%s" % WINDOW_SIZE)
webdriver_service = Service('C:\Users\Sahar\Desktop\bot\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)

CodePudding user response:

Replace the webdriver.Chrome line:

browser=webdriver.Chrome(executable_path=CHROMEDRIVER_PATH,chrome_options=chrome_options)

the executable_path needs to point at the chromedriver.exe. Right now, it's looking at your project directory for chromedriver.exe and not finding it because it is in your desktop.

  • Related