“无法创建Chrome进程”- Selenium Webdriver错误

rm5edbpk  于 2023-06-27  发布在  Go
关注(0)|答案(1)|浏览(220)

我在试着调试为什么我的 selenium 不起作用。我一直在查看Heroku文档,了解如何在部署到Heroku时使用selenium Webdriver,但我最近遇到了这个bug:

Traceback (most recent call last):
  File "C:\Users\IanMurray\Documents\acis\selenium_sandbox.py", line 13, in <module>
    driver = webdriver.Chrome(
  File "C:\Users\IanMurray\Documents\acis\.venv3.9\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 49, in __init__
    super().__init__(
  File "C:\Users\IanMurray\Documents\acis\.venv3.9\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 54, in __init__
    super().__init__(
  File "C:\Users\IanMurray\Documents\acis\.venv3.9\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 206, in __init__
    self.start_session(capabilities)
  File "C:\Users\IanMurray\Documents\acis\.venv3.9\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 291, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
  File "C:\Users\IanMurray\Documents\acis\.venv3.9\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 346, in execute
    self.error_handler.check_response(response)
  File "C:\Users\IanMurray\Documents\acis\.venv3.9\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create Chrome process.
Stacktrace:
Backtrace:
GetHandleVerifier [0x0115A813+48355]
        (No symbol) [0x010EC4B1]
        (No symbol) [0x00FF5358]
        (No symbol) [0x01012026]
        (No symbol) [0x01010579]
        (No symbol) [0x01040C55]
        (No symbol) [0x0104093C]
        (No symbol) [0x0103A536]
        (No symbol) [0x010182DC]
        (No symbol) [0x010193DD]
        GetHandleVerifier [0x013BAABD+2539405]
        GetHandleVerifier [0x013FA78F+2800735]
        GetHandleVerifier [0x013F456C+2775612]
        GetHandleVerifier [0x011E51E0+616112]
        (No symbol) [0x010F5F8C]
        (No symbol) [0x010F2328]
        (No symbol) [0x010F240B]
        (No symbol) [0x010E4FF7]
        (No symbol) [0x75EE00C9]
        RtlGetAppContainerNamedObjectPath [0x77927B4E+286]
        RtlGetAppContainerNamedObjectPath [0x77927B1E+238]

我用下面的代码初始化我的webdriver。这是一个在我的机器上重现bug的最小示例:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

service = Service(ChromeDriverManager().install())
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usages')
options.add_argument('--headless')
options.add_argument('--remote-debugging-port=9222')

driver = webdriver.Chrome(
    service=service,
    options=options
)

print("done")

在没有“driver = webdriver.Chrome(service,options)”行的情况下运行上面的代码可以正常运行,但是没有初始化webdriver。当我尝试运行“driver = webdriver.Chrome()"时,即使没有service/options参数,我也会得到以下错误。
我使用的是Python 3.9.13,selenium版本:如果你需要更多的信息,请告诉我。提前感谢任何帮助。我使用的Chrome版本是:114.0.5735.134,我使用的ChromeDriver版本是:ChromeDriver 114.0.5735.90

f3temu5u

f3temu5u1#

更新到Seleniumv4.10.0,这样您就不会显式地需要WebDriverManager,因为当PATH上没有检测到浏览器驱动程序或没有使用第三方驱动程序管理器时,Selenium绑定会透明地调用完全集成的Selenium Manager
此外,而不是:

options.add_argument('--headless')

使用参数--headless=new

options.add_argument("--headless=new");

解决方案

您的有效代码块将是:

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

options = webdriver.ChromeOptions()
options.add_argument('"--headless=new"')
driver = webdriver.Chrome(options=options)
print("done")

相关问题