2

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?

4 Answers 4

1

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)
Sign up to request clarification or add additional context in comments.

6 Comments

I add the command line for set path and says that a new directory is created. But still it didnt work. I can use webdriver in gitbash command line but can't use it in visual studio code. Is the problem in visual studio code settings?
@SultanMorbiwala, What kind of error do you have? Red underline in pylint?
I says 'executable file may have wrong permission'. my code is driver = webdriver.Chrome() and created a path like you said above
and visual studio code terminal says 'selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see sites.google.com/a/chromium.org/chromedriver/home'
Problem solved, i directly chromedriver from pip. Thanks for the help.
|
1

driver=webdriver.Chrome(executable_path=r'C:\Users\littl\Downloads\chromedriver_win32\chromedriver.exe')

Comments

0

I use Anaconda for which i placed chromedriver.exe in the following

C:\Users\AppData\Local\Continuum\anaconda3\Scripts

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.