0

I'm trying to run Selenium with chrome

I tested this question: WebDriverException: unknown error: cannot find Chrome binary error with Selenium in Python for older versions of Google Chrome

But it generates the error: cannot find Chrome binary

I tested this issue: Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed

But it generates the error: Chrome has crashed

Machine: Ubuntu 16 & Python 3.4

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

options = Options()
options.binary_location = "/usr/local/bin/chromedriver"
options.add_argument("--start-maximized")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'/usr/local/bin/chromedriver')
driver.get('http://google.com/')

output

Traceback (most recent call last):
  File "testdrive.py", line 11, in <module>
    driver = webdriver.Chrome(options=options, executable_path=r'/usr/local/bin/chromedriver')
  File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/local/bin/chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Can someone help me?

1 Answers1

0

Automatically download and install chromedriver that supports the currently installed version of chrome. This installer supports Linux, MacOS and Windows operating systems.

Installation

pip install chromedriver-autoinstaller

Usage

Just type import chromedriver_autoinstaller in the module you want to use chromedriver.

Example

from selenium import webdriver
import chromedriver_autoinstaller


chromedriver_autoinstaller.install()  # Check if the current version of chromedriver exists
                                      # and if it doesn't exist, download it automatically,
                                      # then add chromedriver to path

driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
  • 1
    Don`t working: sudo pip install chromedriver-autoinstaller, output: WARNING: The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. | If i try run, output: Traceback import chromedriver_autoinstaller, from . import utils, logging.debug(f'Downloading chromedriver ({chromedriver_version})...') – DaniloAlbergardi May 26 '21 at 10:37
  • You don't have the appropriate permissions – cruisepandey May 26 '21 at 10:57
  • I believe I have permissions yes, at the end of the message it says: Requirement already satisfied: chromedriver-autoinstaller in /usr/local/lib/python3.4/site-packages (0.2.2) – DaniloAlbergardi May 26 '21 at 11:04