1

I am trying to execute the following code in Python with Selenium:

def create_browser(first_page=None):
    print "Starting"
    browser = webdriver.Chrome()
    if first_page:
        browser.get(first_page);
    print "Done."
    return browser

browser = create_browser()

When I execute this code, Chromium starts but the "Done" statement doesn't get printed. However, if I replace Chrome() by Firefox() the browser starts and "Done" gets printed. I tried to verfiy this in terminal too. If I execute following series of statements:

from selenium import webdriver
driver = webdriver.Chrome()

When I replace Chrome() by Firefox() the terminal returns normally and displays >> (in the python shell but that doesn't happen with Chromium. Can anyone tell what's going wrong here. I really appreciate your help. Thanks!

Update:

I am not sure if this helps but when I execute using webdriver a file called chromedriver.log gets generated in the directory containing my code. It has the following contents:

[0.000][INFO]:      ChromeDriver 20.0.1133.0 /home/therookie/bin/chromedriver
[1.000][FINE]:      Initializing session with capabilities {
   "browserName": "chrome",
   "chromeOptions": {
      "args": [  ],
      "extensions": [  ]
   },
   "javascriptEnabled": true,
   "platform": "ANY",
   "version": ""
}

[1.001][INFO]:      Launching chrome: /usr/bin/google-chrome --disable-hang-monitor --disable-prompt-on-repost --dom-automation --full-memory-crash-report --no-default-browser-check --no-first-run --ignore-certificate-errors --homepage=about:blank
[11.796][SEVERE]:   Failed to initialize connection
ddavison
  • 28,221
  • 15
  • 85
  • 110
TheRookierLearner
  • 3,643
  • 8
  • 35
  • 53

1 Answers1

0

Chrome requires a special file called chromedriver to run. Look here to see what chromedriver is

from selenium import webdriver import os chromedriver = "PATH_TO_CHROMEDRIVER" os.environ["webdriver.chrome.driver"] = chromedriver browser = webdriver.Chrome(executable_path=chromedriver) This should launch Chrome and print done.

amitdatta
  • 760
  • 6
  • 14
  • Actually, if chromedriver is installed anywhere in your path (e.g. you may have installed it via, brew install chromedriver) then webdriver.Chrome() will find it. This is good to know if you have multiple versions of chromedriver in your path, somewhow. – ziff May 11 '19 at 05:55