0

I have seen this question come up a number of times before with good solutions.

In fact, i can get this to work when running code from the editor (VS code). However, when i create a batch file *.bat and try to run the same i get this error message:

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

The batch file calling the code looks like this:

"C:\Program Files\Python39\python.exe" "Y:\path\to\python_file.py"

The exe and the file are in different folders C: and Y:.

I use the usual code for selenium here:

from selenium import webdriver
PATH = r'Y:\some_path_to\chromedriver.exe'
driver = webdriver.Chrome(PATH)

I have tried: https://sites.google.com/chromium.org/driver/getting-started

I have also tried this: Error message: "'chromedriver' executable needs to be available in the path"

I have also tried to change the os.path: https://www.geeksforgeeks.org/python-os-chdir-method/

I have further tried different methods and variations to get the code running from a batch file (again, the same code runs from the VS code editor), but am not sure how to resolve the error ?

extra note: I have also tried to change the path in the windows environment: https://zwbetz.com/download-chromedriver-binary-and-add-to-your-path-for-automated-functional-testing/

But this did not work.

2 Answers2

0

Could it be an issue with your virtual environment? When you run the script from VS Code, by default it uses the selected venv. From .bat file it does not. Try running the script manually but from PowerShell (or cmd) without activating the virtual environment and see if you get the same error.

0

I found this code working for me

Code for python script

import os
import selenium
from selenium import webdriver as wb

webd = wb.Chrome(executable_path=r'D:\Projects\Tools\Chrome Driver\chromedriver.exe')
webd.get('https://selenium-python.readthedocs.io/getting-started.html')

Code for batch file

@echo off
"D:\Projects\Tools\environment\Scripts\python.exe" "D:\Projects\Python Scripts\chrome_driver.py"
pause
Abdul
  • 176
  • 3
  • 19