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

2024-10-04 01:35:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试运行一个简单的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

任何与此相关的帮助都将不胜感激,因为我即将开始使用此软件


Tags: intestvenvseleniumlinechromeusersfile
1条回答
网友
1楼 · 发布于 2024-10-04 01:35:59

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

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

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

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

    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()

相关问题 更多 >