Harry Moreno
Harry Moreno

Reputation: 11603

launch selenium with python on osx

I have the following script

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

opts = Options()
opts.binary_location = "/Applications/Chrome.app/Contents/MacOS/Google\ Chrome"
browser = webdriver.Chrome(chrome_options=opts)
browser.get('0.0.0.0:3500')

assert 'Django' in browser.title

I get the following error after interrupting the program

$ python3 functional_tests.py 
Traceback (most recent call last):
  File "functional_tests.py", line 6, in <module>
    browser = webdriver.Chrome(chrome_options=opts)
  File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 90, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 177, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
  File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: no chrome binary at /Applications/Chrome.app/Contents/MacOS/Google\ Chrome
  (Driver info: chromedriver=2.23.409710 (0c4084804897ac45b5ff65a690ec6583b97225c0),platform=Mac OS X 10.11.6 x86_64)

I have chrome installed on osx. And I know the path to the chrome binary in the script is correct. What may be wrong?

Upvotes: 1

Views: 1779

Answers (1)

elethan
elethan

Reputation: 16993

Try adding the path to your chromedriver binary when you instantiate webdriver.Chrome()

browser = webdriver.Chrome('path/to/my/chomedriver', chrome_options=opts)

The official documentation suggests that you "include the path to ChromeDriver when instantiating webdriver.Chrome" in addition to including the chromedriver location in your PATH variable when you are using it in Python.

If you do not know the location of chromedriver, you can execute brew info chromedriver to see the path in addition to other information.

Upvotes: 2

Related Questions