Selenium with Docker: KeyError status

242 views
Skip to first unread message

Yuya Furusawa

unread,
Jul 11, 2021, 2:37:46 PM7/11/21
to Selenium Users
Hi all,
This is my first post(and first time using google Group), so I'm sorry if this is the wrong way to ask a question.

I have a problem with Docker Selenium.

The Problem Description:

When I run example.py(see below), I got the following error.

% docker-compose exec app python src/example.py
Traceback (most recent call last):
  File "src/example.py", line 13, in <module>
    options=options,
  File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 130, in check_response
    status = value["status"]
KeyError: 'status'

Why I have KeyError?
I can see similar questions, but I have yet to find a solution to this problem.



Directory Structure:

Desktop
└── selenium_example
             ├── docker-compose.yml
             ├── Dockerfile
             ├── requirements.txt
            └── src
                         └── example.py


The Code:

Dockerfile

FROM python:3.9-slim
ENV PYTHONIOENCODING utf-8
RUN mkdir -p /app
WORKDIR /app
COPY ./requirements.txt ./requirements.txt
RUN pip install -r requirements.txt


docker-compose.yml

version: "3"
services:
  selenium:
    image: selenium/standalone-chrome:4.0.0-rc-1-prerelease-20210618
    ports:
      - 4444:4444
      - 5900:5900
    shm_size: "2gb"
  app:
    build: .
    volumes:
      - /path/to/Desktop/selenium_example:/app
    tty: true


requirements.txt

selenium


example.py

from selenium import webdriver

if __name__ == '__main__':
  options = webdriver.ChromeOptions()
  options.add_argument('--headless')
  driver = webdriver.Remote(
    command_executor="http://selenium:4444/wd/hub",
    desired_capabilities=options.to_capabilities(),
    options=options,
  )
  driver.get("https://google.com")
  print(driver.current_url)

  driver.quit()


Extra Info:

macOS Big Sur(version 11.4)
Apple M1


% docker version
Client:
 Cloud integration: 1.0.17
 Version:           20.10.7
 API version:       1.41
 Go version:        go1.16.4
 Git commit:        f0df350
 Built:             Wed Jun  2 11:56:23 2021
 OS/Arch:           darwin/arm64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.7
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       b0f5bc3
  Built:            Wed Jun  2 11:55:36 2021
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.4.6
  GitCommit:        d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc:
  Version:          1.0.0-rc95
  GitCommit:        b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0


% docker-compose exec app pip list
Package    Version
---------- -------
pip        21.1.2
selenium   3.141.0
setuptools 57.0.0
urllib3    1.26.6
wheel      0.36.2

-----

Thank you very much for your help!

Reply all
Reply to author
Forward
0 new messages