My selenium webdrivers will open for afew second, followed by chrome.exe unexpectedly exited

Viewed 113

I am trying to run a simple selenium program that will be able to open a website, but when I enter code the chrome application will open for a few seconds followed my the terminal spitting out the error below. Here is the code I am inserting to pycharm.

from selenium import webdriver

from selenium import webdriver
browser = webdriver.Chrome('C:\Program Files (x86)\Google\Chrome\Application\chrome.exe')

Then this error text is given:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\Billy Kimbell\!Coding!\Projects In Python\test\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\Billy Kimbell\!Coding!\Projects In Python\test\venv\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
    self.assert_process_still_running()
  File "C:\Users\Billy Kimbell\!Coding!\Projects In Python\test\venv\lib\site-packages\selenium\webdriver\common\service.py", line 109, in assert_process_still_running
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service C:\Program Files (x86)\Google\Chrome\Application\chrome.exe unexpectedly exited. Status code was: 0

Any help with this would be much appreciated as I am exited to get started with this software.

1 Answers

I also encountered this problem when all tools' version is right,the follow is my solution:

  1. Go to selenium's folder and find directory of chrome ,my path is this:

    D:\install\python3\Lib\site-packages\selenium\webdriver\chrome

  2. Edit options.py and add path of chrome.exe to _binary_location of init like this:

    class Options(object):

        KEY = "goog:chromeOptions"
    
        def __init__(self):

            self._binary_location = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'   # add chrome path to webdriver
            self._arguments = []
            self._extension_files = []
            self._extensions = []
            self._experimental_options = {}
            self._debugger_address = None
            self._caps = DesiredCapabilities.CHROME.copy()

Related