Python 我的selenium webdrivers将打开几秒钟,然后chrome.exe意外退出

Python 我的selenium webdrivers将打开几秒钟,然后chrome.exe意外退出,python,windows,selenium,pycharm,webautomation,Python,Windows,Selenium,Pycharm,Webautomation,我正在尝试运行一个简单的selenium程序,可以打开一个网站,但是当我 输入代码chrome应用程序将打开几秒钟,然后终端会弹出下面的错误。这是我插入pycharm的代码 from selenium import webdriver from selenium import webdriver browser = webdriver.Chrome('C:\Program Files (x86)\Google\Chrome\Application\chrome.exe') 然后给出该错误文本

我正在尝试运行一个简单的selenium程序,可以打开一个网站,但是当我 输入代码chrome应用程序将打开几秒钟,然后终端会弹出下面的错误。这是我插入pycharm的代码

from selenium import webdriver

from selenium import webdriver
browser = webdriver.Chrome('C:\Program Files (x86)\Google\Chrome\Application\chrome.exe')
然后给出该错误文本:

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
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“C:\Users\Billy Kimbell\!Coding!\Projects In Python\test\venv\lib\site packages\selenium\webdriver\chrome\webdriver.py”,第73行,在\uu init中__
self.service.start()
文件“C:\Users\Billy Kimbell\!Coding!\Projects In Python\test\venv\lib\site packages\selenium\webdriver\common\service.py”,第98行,开始
self.assert\u进程\u仍在运行()
文件“C:\Users\Billy Kimbell\!Coding!\Projects In Python\test\venv\lib\site packages\selenium\webdriver\common\service.py”,第109行,断言进程仍在运行
引发WebDriverException(
selenium.common.exceptions.WebDriverException:消息:服务C:\Program Files(x86)\Google\Chrome\Application\Chrome.exe意外退出。状态代码为:0

非常感谢您对此提供的任何帮助,因为我即将开始使用此软件。

当所有工具的版本都正确时,我也遇到了此问题,以下是我的解决方案:

  • 转到selenium的文件夹并找到chrome的目录,我的路径如下:

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

  • 编辑options.py并将chrome.exe的路径添加到init的_binary_位置,如下所示:


  • 请检查chromedriver和chrome的版本是否相同:)您正在尝试创建一个带有chrome位置的webdriver.chrome实例。不要那样做。它需要的是chromedriver.exe的位置。是的,我已将该位置更改为chrome.exe的更新版本,感谢对有相同问题的任何人的帮助,请在此处获取:
        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()