selenium - 未知错误: Failed to create Chrome process

标签 selenium automated-tests selenium-chromedriver python-3.7

我正在更新 Selenium 和 chromedriver 以进行自动化测试。 我将 chromedriver 和 Chrome 更新到版本 98,并且从 Selenium v​​.3.3.3 升级到 4.1.0。

但是,每当我现在尝试运行测试脚本时,都会遇到未知错误。整个回溯如下:

C:\sw\src\Presentation\client\TestAutomationScripts\TestAutomationScripts\TestPlans>python TestPlan_ATO.py
Traceback (most recent call last):
  File "TestPlan_ATO.py", line 9, in <module>
    class TestPlan_ATO():
  File "TestPlan_ATO.py", line 11, in TestPlan_ATO
    testPlan = Test(name="TestPlan_ATO")
  File "C:\sw\src\Presentation\client\TestAutomationScripts\TestAutomationScripts\TestPlans\TestCases\Test.py", line 113, in __init__
    self.driver = WebDriverInstance().driver
  File "..\Util\WebDriverInstance.py", line 43, in __call__
    cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
  File "..\Util\WebDriverInstance.py", line 97, in __init__
    driver = driverModule(executable_path=driverPath)
  File "..\Util\WebDriverInstance.py", line 73, in createChromeDriver
    driver = webdriver.Chrome(desired_capabilities=capabilities)
  File "C:\Anaconda\lib\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    service_log_path, service, keep_alive)
  File "C:\Anaconda\lib\selenium\webdriver\chromium\webdriver.py", line 99, in __init__
    options=options)
  File "C:\Anaconda\lib\selenium\webdriver\remote\webdriver.py", line 269, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Anaconda\lib\selenium\webdriver\remote\webdriver.py", line 360, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Anaconda\lib\selenium\webdriver\remote\webdriver.py", line 425, in execute
    self.error_handler.check_response(response)
  File "C:\Anaconda\lib\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create Chrome process.
Stacktrace:
Backtrace:
        Ordinal0 [0x00317AC3+2587331]
        Ordinal0 [0x002AADD1+2141649]
        Ordinal0 [0x001A3BB8+1063864]
        Ordinal0 [0x001BF684+1177220]
        Ordinal0 [0x001BCC51+1166417]
        Ordinal0 [0x001ED12F+1364271]
        Ordinal0 [0x001ECD5A+1363290]
        Ordinal0 [0x001E84A6+1344678]
        Ordinal0 [0x001C53F6+1201142]
        Ordinal0 [0x001C62E6+1204966]
        GetHandleVerifier [0x004BDF22+1680738]
        GetHandleVerifier [0x00570DBC+2413564]
        GetHandleVerifier [0x003AD151+563089]
        GetHandleVerifier [0x003ABF13+558419]
        Ordinal0 [0x002B081E+2164766]
        Ordinal0 [0x002B5508+2184456]
        Ordinal0 [0x002B5650+2184784]
        Ordinal0 [0x002BF5BC+2225596]
        BaseThreadInitThunk [0x75A4FA29+25]
        RtlGetAppContainerNamedObjectPath [0x77107A9E+286]
        RtlGetAppContainerNamedObjectPath [0x77107A6E+238]
        (No symbol) [0x00000000]

我的 PATH 中有 Chrome,但这似乎没有什么区别。在 Chrome 属性的“兼容性”选项卡下,我选中了“以管理员身份运行此程序”,但同样不起作用。我不知道还能做什么。

编辑 1:

Anaconda 发行版位于我的 C 驱动器上。 selenium 目录位于 Anaconda 目录内。当我更新 selenium 时,我在回溯中得到了 ModuleNotFoundError: 'certifi':

Traceback (most recent call last):
  File "TestPlan_ATO.py", line 2, in <module>
    from TestCases.Test import Test
  File "C:\sw\src\Presentation\client\TestAutomationScripts\TestAutomationScripts\TestPlans\TestCases\Test.py", line 72, in <module>
    from Util.WebDriverEventListener import WebDriverEventListener as Listener
  File "..\Util\WebDriverEventListener.py", line 25, in <module>
    from selenium.webdriver.support.events import AbstractEventListener
  File "C:\Anaconda\lib\selenium\webdriver\__init__.py", line 18, in <module>
    from .firefox.webdriver import WebDriver as Firefox  # noqa
  File "C:\Anaconda\lib\selenium\webdriver\firefox\webdriver.py", line 24, in <module>
    from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
  File "C:\Anaconda\lib\selenium\webdriver\remote\webdriver.py", line 39, in <module>
    from .remote_connection import RemoteConnection
  File "C:\Anaconda\lib\selenium\webdriver\remote\remote_connection.py", line 26, in <module>
    import certifi
ModuleNotFoundError: No module named 'certifi'

为了修复此错误,我进入 remote_connection.py 并将下面的前两行添加到文件中。

import sys
sys.path.append('/Anaconda/Lib/site-packages/pip/_vendor')

import logging
import socket
import string

import os
import certifi
import urllib3
import platform

然后,我收到另一个错误,提示 testcase.ini,该配置文件包含被测系统的 IP、应用程序的登录信息等。

Cannot load C:\Anaconda\Lib\site-packages\pip\_vendor\TestPlans\TestCases\testcase.ini
Traceback (most recent call last):
  File "TestPlan_ATO.py", line 5, in <module>
    from TestCases.ATO.TestCase_ATO import TestCase_ATO
  File "C:\sw\src\Presentation\client\TestAutomationScripts\TestAutomationScripts\TestPlans\TestCases\ATO\TestCase_ATO.py", line 22, in <module>
    from Util.UiOps import UiOps as ops
  File "..\Util\UiOps.py", line 37, in <module>
    class UiOps:
  File "..\Util\UiOps.py", line 40, in UiOps
    config.load('','testcase.ini')
  File "..\Util\ConfigManager.py", line 114, in load
    new_dict: dict = self.loader.loadFile(package=package, module=module, filename=filename)
  File "..\Util\ConfigLoader.py", line 96, in loadFile
    raise IOError('Cannot load ' + config_file)
OSError: Cannot load C:\Anaconda\Lib\site-packages\pip\_vendor\TestPlans\TestCases\testcase.ini

每次运行自动化测试时都会读取 testcase.ini。 ConfigLoader 类返回一个配置对象,给定模块名称和相对于 ConfigLoader 的文件路径。因此,我进入 ConfigLoader.py 并将下面的 try/except block 中的 -1 更改为 -2 :

try:
    
    if self.package:
        #If a package is given, use the last entry in sys.path which goes up a directory, and drill down into the package
        path =  sys.path[-2] + "//" + self.package
    else:
        #If not, use the information stored in sys.path, and assume we want to look in TestPlans/TestCases
        path = sys.path[-2] + "//TestPlans//TestCases"

这就是我如何得出我第一次发布的未知错误的原因。

testcase.ini 也是选择浏览器和存储驱动程序路径的位置。它看起来像这样:

; parameters for test framework
[TEST]
DRIVER_PATH = C:\Anaconda\
BROWSER = CHROME
; BROWSER = EDGE
; BROWSER = FIREFOX
CHROME_PATH = C:\Program Files\Google\Chrome\Application\chrome.exe
; EDGE_PATH = C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
; FIREFOX_PATH = C:\Program Files\Mozilla Firefox\firefox.exe

最佳答案

chrome.exe 有两份副本,一份位于 Program Files 中,另一份位于 Program Files (x86) 中。我不知道为什么在两个不同的C盘子目录中有两个独立的Google目录。 无论如何,我删除了 Program Files 中的 Google 目录并将其保留在 (x86) 中,现在我的测试脚本再次运行。

关于selenium - 未知错误: Failed to create Chrome process,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71340051/

相关文章:

vue.js - 如何使用 vue.js v-select 通过 cypress.io 查找元素和选择?

installation - 配置 Rational Functional Tester (RFT) 以在 Hudson/Jenkins 中运行

google-chrome - 在 selenium chromedriver 上运行的远程调试 Internjs

C# Selenium ChromeDriver - 如何抑制打印预览,pdf

python - 如何使用 chromedriver 在 chromium-embedded 中设置用户数据目录?

python - 使用 Python 教程进行测试驱动开发 : Error trying to open Firefox with Selenium on MacOSX

java - 如何在类中使用字符串作为变量传递字符串作为参数

javascript - TestCafe错误: "No tests to run. Either the test files contain no tests or the filter function is too restrictive"

Python。 Selenium 。拖放错误 'AttributeError: move_to requires a WebElement'

Python 3.6 - 使用 google-image-download 进行图像抓取