0

I wrote this code which is in selenium webdriver in python.

I want to open link in chrome browser, the browser is getting started but can't fetch url.

def setUp(self):
    self.browser = webdriver.Chrome("/usr/bin/google-chrome")
    browser = self.browser
    browser.implicitly_wait(5)
    browser.get("http://www.google.com")

This gives this error:

ERROR: test_start (__main__.Saletest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "sale_test.py", line 16, in setUp
self.browser = webdriver.Chrome("/usr/bin/google-chrome")
File "/usr/local/lib/python2.7/dist-    packages/selenium/webdriver/chrome/webdriver.py", line 60, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/service.py", line 88, in start
os.path.basename(self.path) + "'")
WebDriverException: Message: Can not connect to the 'google-chrome'
SuperBiasedMan
  • 9,814
  • 10
  • 45
  • 73
sakib keriwala
  • 129
  • 3
  • 14
  • so what's the solution , I want to run in chrome webdriver – sakib keriwala Dec 18 '15 at 12:09
  • You need the ChromeDriver binary, not the chrome browser binary. Please read the question I linked – Noel Segura Meraz Dec 18 '15 at 12:16
  • Don't think this is an exact duplicate of [Running webdriver chrome with Selenium](http://stackoverflow.com/questions/8255929/running-webdriver-chrome-with-selenium) - here we have a Google Chrome vs chromedriver confusion. – alecxe Dec 18 '15 at 14:45

2 Answers2

0

Basically Selenium find your binary, but can't connect to it.

Try this, this seems to correspond to your problem :) WebDriverException: Message: 'Can not connect to the ChromeDriver'. Error in utils.is_connectable(self.port):

Community
  • 1
  • 1
Louis Ventre
  • 131
  • 5
  • I also made my file executable and followed the link steps but same error arrises – sakib keriwala Dec 18 '15 at 12:50
  • Did you read the link of Noel Segura ? (http://stackoverflow.com/questions/8255929/running-webdriver-chrome-with-selenium) Here is some doc too http://selenium-python.readthedocs.org/en/latest/api.html#module-selenium.webdriver.chrome.webdriver – Louis Ventre Dec 18 '15 at 12:54
0

The first argument that webdriver.Chrome expects to be provided with is the executable_path - a path to the chromedriver, but you are passing a path to the Chrome itself.

The executable_path argument is optional. In case chromedriver is in PATH and selenium can automatically find it, you don't need to explicitly state where it is located.

If you want to provide a custom Chrome browser executable instead, define the Chrome binary location via ChromeOptions:

options = Options()
options.binary_location = "/path/to/google-chrome"
driver = webdriver.Chrome(chrome_options=options)

And, just for completeness, here is how would the setup look in case you have a custom chromedriver path and a custom Chrome browser binary path:

options = Options()
options.binary_location = "/path/to/google-chrome"
driver = webdriver.Chrome(executable_path="/path/to/chromedriver", 
                          chrome_options=options)
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195