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
  • 761
  • 3
  • 13
  • 33
  • 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

6 Answers6

11

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
  • 8,172
  • 3
  • 45
  • 66
10

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
  • 954
  • 1
  • 13
  • 17
  • 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
  • 1
    @bgoodr: then please repost that rewritten as "Note to historical users of conda x.xx" instead of the more alarming "Warning to future readers" – smci Sep 07 '22 at 14:19
  • 1
    @smci I would like to do that, but adding a new post here to restate [my older comment](https://stackoverflow.com/questions/38876281/anaconda-selenium-and-chrome/55973176?noredirect=1#comment99366368_55973176) might confuse future readers. Hopefully they will read your comment, and this one here, and do the edits in their minds. Truth be told, dear readers, you need to take my earlier comments with great suspicion because it is now 2022-09-09 and maybe the maintainers of Anaconda, conda, `python-chrome-driver-binary`, etc. have since addressed the issue I raised. – bgoodr Sep 09 '22 at 13:09
3
  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
  • 761
  • 3
  • 13
  • 33
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,583
  • 5
  • 22
  • 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
0

When I tried installing chromedriver_binary as suggested in other answers, I got version incompatibility for my installed version of chrome. The chromedriver_binary_auto library automatically detects your chrome version and downloads the right driver:

pip install chromedriver-binary-auto

You import it just like you would import chromedriver_binary.

import chromedriver_binary  # Adds chromedriver binary to path
Jacob Stern
  • 3,758
  • 3
  • 32
  • 54
-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,227
  • 1
  • 12
  • 17