Reputation: 171
I installed selenium and downloaded chromedriver.exe When i run the code in my gitbash terminal then its working but not working when I run a python script in visual studio code.
On internet it say to put the file in the path but i don't know much about it. Where should i place the chromedriver.exe?
Upvotes: 2
Views: 7112
Reputation: 255
driver=webdriver.Chrome(executable_path=r'C:\Users\littl\Downloads\chromedriver_win32\chromedriver.exe')
Upvotes: 1
Reputation: 193128
Short answer is anywhere
As per your question you can put the ChromeDriver anywhere within your local system and when you initialize the WebDriver and Web Browser pass the Key executable_path mentioning the absolute path of the ChromeDriver as follows:
Windows OS style
driver=webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe')
Linux OS style
driver=webdriver.Chrome(executable_path='/path/to/chromedriver')
MacLinux OS X style
driver=webdriver.Chrome(executable_path='/path/to/chromedriver')
Note: Avoid accessing ChromeDriver placed in shared drives.
Upvotes: 0
Reputation: 31
I use Anaconda for which i placed chromedriver.exe in the following
C:\Users\AppData\Local\Continuum\anaconda3\Scripts
Upvotes: 0
Reputation: 2502
Simple answer is Anywhere.
Add the path for where you put the driver by command line:
set PATH=%PATH%;C:\WHERE_I_PUT_THEDRIVER\
Or
In Your Control Panel -> All Control Panel Items -> System -> Advanced System Setting -> Advanced -> Environment Variable -> System Variable -> [Choose] Path -> [Click] Edit
So when you import it.
from selenium import webdriver
wd = webdriver.Chrome()
Or, if you prefer not to add new path,
from selenium import webdriver
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
#__location__ is current file location
driver_loca = os.path.join(__location__, 'bin/chromedriver.exe')
wd = webdriver.Chrome(executable_path= driver_loca)
Upvotes: 1