Selenium+chromedriver and python - how to make it work?

I’m trying to integrate my test_page.py selenium script with circleCI, but after 30 tries it still doesn’t work for me. I’m using chromedriver and python btw. Below is my ACTUAL config.yml, cuz I changed it 10 times - so it uses orb in this case. Without orb it doesn’t work, too.

version: 2.1
orbs:
  browser-tools: circleci/browser-tools@1.4.0
jobs:
  build:
    docker:
      - image: circleci/python:3.8
      - image: selenium/standalone-chrome:3.11.0
      - image: cimg/node:19.3.0-browsers
    steps:
      - browser-tools/install-chrome
      - browser-tools/install-chromedriver
      - checkout
      - run:
          command: |
            google-chrome --version
            chromedriver --version
      - run:
          name: Upgrade pip
          command: |
            pip install --upgrade pip
      - run:
          name: Install Dependencies
          command: |
            pip install -r requirements.txt
      - run:
          name: Run Selenium Tests
          command: |
            python -m pytest test_page.py

It gives me error, like below:

============================= test session starts ==============================
platform linux -- Python 3.8.12, pytest-7.2.0, pluggy-1.0.0
rootdir: /home/circleci/project
collecting ... 
collecting 0 items / 1 error                                                   
collected 0 items / 1 error                                                    

==================================== ERRORS ====================================
________________________ ERROR collecting test_page.py _________________________
test_page.py:14: in <module>
    browser = webdriver.Chrome()
../.local/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py:81: in __init__
    super().__init__(
../.local/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py:106: in __init__
    super().__init__(
../.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py:288: in __init__
    self.start_session(capabilities, browser_profile)
../.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py:381: in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
../.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py:444: in execute
    self.error_handler.check_response(response)
../.local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py:249: in check_response
    raise exception_class(message, screen, stacktrace)
E   selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
E     (unknown error: DevToolsActivePort file doesn't exist)
E     (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
E   Stacktrace:
E   #0 0x560569fb72a3 <unknown>
E   #1 0x560569d75f77 <unknown>
E   #2 0x560569d9e5f7 <unknown>
E   #3 0x560569d9a7d0 <unknown>
E   #4 0x560569ddb0b7 <unknown>
E   #5 0x560569ddaa5f <unknown>
E   #6 0x560569dd2903 <unknown>
E   #7 0x560569da5ece <unknown>
E   #8 0x560569da6fde <unknown>
E   #9 0x56056a00763e <unknown>
E   #10 0x56056a00ab79 <unknown>
E   #11 0x560569fed89e <unknown>
E   #12 0x56056a00ba83 <unknown>
E   #13 0x560569fe0505 <unknown>
E   #14 0x56056a02cca8 <unknown>
E   #15 0x56056a02ce36 <unknown>
E   #16 0x56056a048333 <unknown>
E   #17 0x7f4f97711ea7 start_thread
=========================== short test summary info ============================
ERROR test_page.py - selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
#0 0x560569fb72a3 <unknown>
#1 0x560569d75f77 <unknown>
#2 0x560569d9e5f7 <unknown>
#3 0x560569d9a7d0 <unknown>
#4 0x560569ddb0b7 <unknown>
#5 0x560569ddaa5f <unknown>
#6 0x560569dd2903 <unknown>
#7 0x560569da5ece <unknown>
#8 0x560569da6fde <unknown>
#9 0x56056a00763e <unknown>
#10 0x56056a00ab79 <unknown>
#11 0x560569fed89e <unknown>
#12 0x56056a00ba83 <unknown>
#13 0x560569fe0505 <unknown>
#14 0x56056a02cca8 <unknown>
#15 0x56056a02ce36 <unknown>
#16 0x56056a048333 <unknown>
#17 0x7f4f97711ea7 start_thread
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.89s ===============================

Exited with code exit status 2

And below is how start of my original test_page.py file looks like:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import Select
import time
import pyautogui
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
s=Service('C:\Program Files\chromedriver.exe')
browser = webdriver.Chrome(service=s)

Make note, that in my circleci file it looks different - here is no more ‘s=Service’ and here’s browser = webdriver.Chrome() INSTEAD of browser = webdriver.Chrome(service=s).

It doesn’t work for me with or without orb, with s=service or not, or just with different path in s=service, too - nothing worked.

EDIT
here’s different config.yml I tried:

version: 2.1
jobs:
  build:
    docker:
      - image: circleci/python:3.8
      - image: selenium/standalone-chrome:3.11.0
    steps:
      - checkout
      - run:
          name: Upgrade pip
          command: |
            pip install --upgrade pip
      - run:
          name: Install Dependencies
          command: |
            pip install -r requirements.txt
      - run:
          name: Run Selenium Tests
          command: |
            python -m pytest test_page.py

And below is error:


#!/bin/bash -eo pipefail
python -m pytest test_page.py
============================= test session starts ==============================
platform linux -- Python 3.8.12, pytest-7.2.0, pluggy-1.0.0
rootdir: /home/circleci/project
collecting ... collecting 0 items / 1 error                                                   collected 0 items / 1 error                                                    

==================================== ERRORS ====================================
________________________ ERROR collecting test_page.py _________________________
test_page.py:14: in <module>
    browser = webdriver.Chrome()
../.local/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py:81: in __init__
    super().__init__(
../.local/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py:103: in __init__
    self.service.start()
../.local/lib/python3.8/site-packages/selenium/webdriver/common/service.py:106: in start
    self.assert_process_still_running()
../.local/lib/python3.8/site-packages/selenium/webdriver/common/service.py:119: in assert_process_still_running
    raise WebDriverException(f"Service {self.path} unexpectedly exited. Status code was: {return_code}")
E   selenium.common.exceptions.WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127
=========================== short test summary info ============================
ERROR test_page.py - selenium.common.exceptions.WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.88s ===============================

Exited with code exit status 2
CircleCI received exit code 2
CircleCI