admin管理员组

文章数量:1127991

I get the following selenium error when running it in docker:

seleniummon.exceptions.SessionNotCreatedException: Message: Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: disconnected: Unable to receive message from renderer (failed to check if window was closed: disconnected: not connected to DevTools) (Session info: chrome=131.0.6778.204) Host info: host: 'a7476dd91767', ip: '172.18.0.2' Build info: version: '4.27.0', revision: 'd6e718d' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.167.4-microsoft-standard-WSL2', java.version: '17.0.13' Driver info: driver.version: unknown

I already tried a combination of a selenium/standalone-chrome and a python container:

services:
  python:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - .:/app
    depends_on:
      selenium:
        condition: service_healthy
    environment:
      - DISPLAY=:99.0  #Headless-Browser display pipe
    command: python /app/extract_octopus_price.py
    platform: linux/amd64

  selenium:
    image: selenium/standalone-chrome:latest
    shm_size: 2g
    platform: linux/amd64
    ports:
      - "4444:4444"
      - "7900:7900"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:4444/status"]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 10s

With the target code:

chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")

if __name__ == "__main__":

    driver = webdriver.Remote(
                command_executor='http://selenium:4444',
                options=chrome_options
            )
    driver.get("/")
    print(driver.page_source)
    driver.quit()

And a single instance with:

FROM python:3.10

COPY requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r /app/requirements.txt

RUN apt-get update && apt-get install -y wget unzip && \
    wget .deb && \
    apt install -y ./google-chrome-stable_current_amd64.deb && \
    rm google-chrome-stable_current_amd64.deb && \
    apt-get clean

WORKDIR /app

ENV DISPLAY=:99

With the target code:

chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")

if __name__ == "__main__":

    service = Service(ChromeDriverManager().install())
    driver = webdriver.Chrome(service=service, options=chrome_options)
    driver.get("/")
    print(driver.page_source)
    driver.quit()

But on both I get the error mentioned above. I hope someone has an idea. Thanks!

Chrome: 131.0 selenium==4.27.1 webdriver-manager==4.0.2 selenium/standalone-chrome:4.27.0

And if this matters in some way: I'm executing Docker Desktop (Windows 11 on ARM) on a ARM64 machine. The Python code is running native on this machine with latest Chrome installation.

本文标签: