12

I am running selenium through anaconda on my mac. To be able to choose Chrome as my webdriver I need to download the latest chromedriver. But I can't figure out where to put the file for it to be in path. If I just run

driver = webdriver.Chrome()

WebDriverException: Message: unknown error: cannot find Chrome binary

Should I put chromedriver in anaconda/lib/python2.7/site-packages/selenium/webdriver/ and if so how do I specify selenium to use it?

I know it has to be something simple, since I have already set up chromedriver on my other computer like a year ago, but I don't have access to it right now.

EDIT: tried this

import os
from selenium import webdriver

chromedriver = "/Users/username/Downloads/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get("http://stackoverflow.com")
driver.quit()

Got this error:

WebDriverException: Message: unknown error: cannot find Chrome binary
  (Driver info: chromedriver=2.23.409710 (0c4084804897ac45b5ff65a690ec6583b97225c0),platform=Mac OS X 10.11.6 x86_64)
AK9309
  • 731
  • 3
  • 13
  • 32
  • Have a look here http://stackoverflow.com/questions/8255929/running-webdriver-chrome-with-selenium – Saurabh Gaur Aug 10 '16 at 14:43
  • Saw that thread, and tried adam goucher's answer, but get the same error. I don't think instaling brew would work any better since I need to get the driver installed in a way that anaconda can use it. – AK9309 Aug 10 '16 at 14:49
  • For me the only thing that worked was here: https://stackoverflow.com/questions/63421086/modulenotfounderror-no-module-named-webdriver-manager-error-even-after-instal – bart cubrich Nov 02 '21 at 19:54

5 Answers5

11

The easiest would be to install chrome-driver via anaconda (especially when running on a machine where you don't have permissions to install chrome-driver from .deb package)

conda install -c conda-forge python-chromedriver-binary 

(updated based on comment from bgoodr (https://stackoverflow.com/users/257924/bgoodr) - please vote his comment below ).

Mircea
  • 914
  • 1
  • 12
  • 16
  • 9
    Warning to future readers: If you install that one from anaconda into a conda env that contains python3, it will "supercede" that python _back_ to python2 and much wailing and gnashing of teeth will result. Instead pull the package from the conda-forge channel via something like `conda install -n envpython3 -c conda-forge python-chromedriver-binary`. Compare the huge difference in download counts between the anaconda version versus the conda-forge version, at https://anaconda.org/search?q=chromedriver – bgoodr May 30 '19 at 17:38
  • Maybe I'm misunderstanding the comment above, but installing this package in a python 3.8 env does not downgrade python; it just installs this one package for me. In any case, if you want to try it, just try the command given, and it will ask for confirmation before changing anything in your env. – Mike Feb 07 '21 at 14:22
  • 2
    @Mike That comment was from almost two years ago, the problem does not exist anymore :) – bugmenot123 Feb 08 '21 at 14:24
8

The simplest solution is to install chromedriver as suggested by @bgodr:

conda install -c conda-forge python-chromedriver-binary

Then at the top of your code, add the following import statement to update your PATH variable appropriately:

import chromedriver_binary
David Marx
  • 7,546
  • 3
  • 40
  • 61
2
  1. Download latest chromedriver
  2. Update Chrome itself
  3. In your code

from selenium import webdriver driver_path = '/path to chromedriver.exe/' driver = webdriver.Chrome(driver_path) driver.get('somewebsite')

AK9309
  • 731
  • 3
  • 13
  • 32
0

I tried this:

conda install selenium-chromedriver

Then do the following in python:

from selenium import webdriver
browser = webdriver.Chrome()

It worked.

midtownguru
  • 2,414
  • 4
  • 20
  • 24
  • https://anaconda.org/search?q=selenium-chromedriver -- please specify which channel. also, the package doesn't seem maintained. I suggest using python-chromedriver-binary instead. This still requires google-chrome to be installed on the machine. – Mircea May 03 '19 at 16:20
-1

You can start up your selenium server and specify where the chrome driver is:

java -jar selenium.jar -Dwebdriver.chrome.driver=/~path/chromedriver
Moe Ghafari
  • 2,067
  • 10
  • 17