Search code examples
pythongoogle-chromeseleniumselenium-webdriverchrome-web-driver

how do i start Chromedriver not with the default profile?


I'm trying to load Chrome with Chromedriver and a non default profile.
I'm using this python code:

opt = webdriver.ChromeOptions()
chromedriver = r"C:/chromedriver/chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
opt.add_argument(r"user-data-dir=C:\Users\user\AppData\Local\Google\Chrome\User Data\Default_Selenium")
driver = webdriver.Chrome(opt)


but i'm getting the following error:

Traceback (most recent call last):
  File "C:\Users\user\workspace\dd\src\start.py", line 29, in <module>
    main()
  File "C:\Users\user\workspace\dd\src\start.py", line 20, in main
    driver = webdriver.Chrome(opt)
  File "C:\Python27\Lib\site-packages\selenium-2.43.0-py2.7.egg\selenium\webdriver\chrome\webdriver.py", line 59, in __init__
    self.service.start()
  File "C:\Python27\Lib\site-packages\selenium-2.43.0-py2.7.egg\selenium\webdriver\chrome\service.py", line 68, in start
    and read up at http://code.google.com/p/selenium/wiki/ChromeDriver")
selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path.                 Please download from http://chromedriver.storage.googleapis.com/index.html                and read up at http://code.google.com/p/selenium/wiki/ChromeDriver' 

what am i doing wrong?


Solution

  • The chromedriver executable should be either available in PATH environment variable, or set explicitly via executable_path argument to Chrome():

    driver = webdriver.Chrome(executable_path=r'C:/chromedriver/chromedriver.exe',
                              chrome_options=opt)