12

I am running a Docker image from a Docker container in AWS Batch environment. It was all working nicely for a while now, but since today I am getting the following error.

E   selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This 
version of ChromeDriver only supports Chrome version 114
E   Current browser version is 116.0.5845.96 with binary path /opt/google/chrome/google-chrome

The Dockerfile that has the chrome installation is as below

FROM python:3.10
WORKDIR /usr/src/app
COPY . .

RUN pip install --trusted-host pypi.org --upgrade pip
RUN pip install --no-cache-dir \
--extra-index-url https://artifactory.int.csgdev01.citcosvc.com/artifactory/api/pypi/citco- 
pypi/simple \
-r requirements.txt

RUN pip install awscli

RUN apt-get install -yqq unzip curl
RUN apt-get -y update
RUN apt-get install zip -y
RUN apt-get install unzip -y
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> 

/etc/apt/sources.list.d/google-chrome.list RUN apt-get -y update RUN apt-get -y install -y google-chrome-stable

# Install chrome driver
RUN wget -N https://chromedriver.storage.googleapis.com/`curl -sS 
chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip -P ~/
RUN unzip ~/chromedriver_linux64.zip -d ~/
RUN rm ~/chromedriver_linux64.zip
RUN mv -f ~/chromedriver /usr/local/bin/chromedriver
RUN chmod 0755 /usr/local/bin/chromedriver
RUN ls -lt
RUN ls -lt /usr/local/bin
RUN chmod +x ./run.sh
CMD ["bash", "./run.sh"]

My selenium python test class is below

from selenium import webdriver
import unittest
class Test_SecTransferWorkflow(unittest.TestCase):
    options = webdriver.ChromeOptions()
    options.add_argument('--no-sandbox')
    options.add_argument("--enable-javascript")
    options.add_argument("--start-maximized")
    options.add_argument("--incognito")
    options.add_argument('--headless')
    options.add_argument('--ignore-certificate-errors')
    options.add_argument('--enable-features=NetworkService')
    options.add_argument('--shm-size=1g')
    options.add_argument('--disable-gpu')
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_argument("--window-size=1920,1080")
    options.add_argument("--disable-extensions")
    options.add_argument('--disable-dev-shm-usage')
    options.add_experimental_option('useAutomationExtension', False)
    options.add_experimental_option("detach", True)
    options.add_argument('--allow-running-insecure-content')
    options.add_argument('--allow-insecure-localhost')
    options.add_argument('--ignore-ssl-errors=yes')
    options.add_argument('--user-agent=Chrome/77')
    driver = webdriver.Chrome(options=options)

    @classmethod
    def setUpClass(cls):
        try:
            cls.driver.delete_all_cookies()
            cls.driver.get(TestData_common.BASE_URL)
            time.sleep(2)
        except WebDriverException as e:
            print('Site down...> ', e)
            cls.driver.delete_all_cookies()
        time.sleep(3)

    def test_001_login(self):
        if not TestData_common.URL_FOUND:
            pytest.skip('Site seems to be down...')
        self.loginPage = LoginPage(self.driver)
        self.loginPage.do_click_agree_button()
        self.driver.maximize_window()
        print('Successfully clicked on AGREE button...')
        time.sleep(2)

I didn't have any issues running this image so far, until I encountered this error today. Any help is much appreciated.

Ram
  • 155
  • 1
  • 5
  • The version of Chrome and Chromedriver do not match. The reason for this is because chromedriver and chrome are not released together at the same time. In this case, the latest version of Chrome (116) is ahead of the latest version of chromedriver (114). You should not rely on the latest versions of these repos being matching versions. – sytech Aug 15 '23 at 23:25
  • Thank you v much. I've few questions on this. 1.How come I didn't have any issues so far (its been running for months now) and suddenly today? 2.If I should not rely on latest versions of these repos, how do I know which chrome version should I install in the Docker? This whole setup is run from AWS Batch environment in a linux OS. 3.How do I install specific version of chrome from the Docker file? – Ram Aug 15 '23 at 23:56
  • 1. It worked previously because the latest versions _happened_ to match in the past -- and they often will, but this is not guaranteed, as you're now seeing 2. You should inspect the version of chrome to determine the version of chromedriver to install -- or vice versa. 3. To install a particular version of chrome, just download the `.deb` file for the version you want to install -- see: [here](https://unix.stackexchange.com/q/233185) for more info. You can also find the Chromedriver downloads for 116 here: https://googlechromelabs.github.io/chrome-for-testing/#stable – sytech Aug 16 '23 at 00:15
  • Does this answer your question? [selenium.common.exceptions.SessionNotCreatedException: This version of ChromeDriver only supports Chrome version 114. LATEST\_RELEASE\_115 doesn't exist](https://stackoverflow.com/questions/76913935/selenium-common-exceptions-sessionnotcreatedexception-this-version-of-chromedri) – Gugu72 Aug 23 '23 at 12:26

6 Answers6

3

The versions of chrome (116) and chromedriver (114) do not match. This is because the latest version of chromedriver (as described by chromedriver.storage.googleapis.com/LATEST_RELEASE) is not necessarily always going to match the latest version of Chrome from the debian repo. Although these major versions will often match (which is why this has worked for you in the past), you cannot rely on this to be the case all the time, as you're now seeing.

Instead, you should inspect the version of chrome and then install an appropriate version of chromedriver. As described on the chromedriver downloads page, you can use their API endpoint to find download links for various versions of chromedriver or find the links on the dashboard, both of which will include links to download versions of chromedriver that are compatible with chrome 116 -- for example at the time of writing: https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chromedriver-linux64.zip (but be aware this zip structure may be different than the download links you're already using).

In my own dockerfile, I specify the chromedriver download URL manually and just run a script to test that the major versions match. Though, you could use the API endpoint mentioned above to automate getting the correct chromedriver URL.


As for why chromedriver.storage.googleapis.com/LATEST_RELEASE points to major version 114 instead of 116, despite a download being available for 116 and the stable debian version being 116, I'm not really sure, to be honest.

sytech
  • 29,298
  • 3
  • 45
  • 86
  • Thank you for your suggestion, really appreciate it. I tried installing RUN wget -N https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chromedriver-linux64.zip -P ~/ from Dockerfile and it worked. I am still not sure how to overcome this hard coded chrome version in the Dockerfile. Tomorrow if the chrome version changes, should I edit my Dockerfile and put that version in? Can you show me how to do this automatically? Sorry not a Docker expert. – Ram Aug 16 '23 at 12:36
  • Thanks for providing this answer, with an explanation for the issue and the URL for the right driver. It has worked for me. Selenium version `selenium==4.11.2`, `chromium=116.0.5845.96 `. – morallito Aug 23 '23 at 13:21
2

As above, https://chromedriver.chromium.org/downloads now suggests getting the download of chromedriver from https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json

Try this out to get the latest v116:

export CHROMEDRIVER_VERSION=116
export CHROMEDRIVER_URL=$(curl -s https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json | \
  jq -r --arg version "$CHROMEDRIVER_VERSION" '[.versions[] | select(.version | startswith($version + "."))] | last | .downloads.chromedriver[] | select(.platform == "linux64").url')

(This assumes that the JSON file is sorted with older to newest, so we want the last one with version="160.x.y.z".)

Note, the downloaded .zip is now a folder chromedriver-linux64 containing chromedriver executable.

In a Dockerfile, try:

ARG CHROMEDRIVER_VERSION='116'

# Install Chrome WebDriver
RUN CHROMEDRIVER_URL=$(curl -s https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json | \
  jq -r --arg version "$CHROMEDRIVER_VERSION" '[.versions[] | select(.version | startswith($version + "."))] | last | .downloads.chromedriver[] | select(.platform == "linux64").url') && \
  mkdir -p /opt/chromedriver-$CHROMEDRIVER_VERSION && \
  curl -sS -o /tmp/chromedriver_linux64.zip "$CHROMEDRIVER_URL" && \
  unzip -qq /tmp/chromedriver_linux64.zip -d /opt/chromedriver-$CHROMEDRIVER_VERSION && \
  rm /tmp/chromedriver_linux64.zip && \
  chmod +x /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver-linux64/chromedriver && \
  ln -fs /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver-linux64/chromedriver /usr/local/bin/chromedriver

FWIW, gpt4 helped me write the jq clause to parse the JSON

https://chat.openai.com/share/ebe38666-9ea7-4bd4-9935-5430fec339f5

Also, here are all the other platforms available if you replace select(.platform == "linux64") with one of the platforms below:

curl -s https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json | \
jq '[.versions[] | select(.version | startswith("116."))] | last | .downloads.chromedriver'

[
  {
    "platform": "linux64",
    "url": "..."
  },
  {
    "platform": "mac-arm64",
    "url": "..."
  },
  {
    "platform": "mac-x64",
    "url": "..."
  },
  {
    "platform": "win32",
    "url": "..."
  },
  {
    "platform": "win64",
    "url": "..."
  }
]
Dr Nic
  • 2,072
  • 1
  • 15
  • 19
  • 1
    There are other JSON URLs listed here: https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints For example this one gives you the last version: https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json – Dmitry Shvedov Aug 19 '23 at 22:02
0

My guess is that you are on older version of selenium. Selenium version 4.10.0 or below will not support latest version of chrome browser.

Solution: Upgrade selenium version to v4.11.2. This should resolve the issue.

Shawn
  • 4,064
  • 2
  • 11
  • 23
  • 2
    Thank you. Unfortunately upgrading selenium to 4.11.2 didn't solve the problem. – Ram Aug 16 '23 at 12:39
0

To install the latest Chrome and Chromedriver in Docker:

# Install latest Chrome
RUN CHROME_URL=$(curl -s https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json | jq -r '.channels.Stable.downloads.chrome[] | select(.platform == "linux64") | .url') \
    && curl -sSLf --retry 3 --output /tmp/chrome-linux64.zip "$CHROME_URL" \
    && unzip /tmp/chrome-linux64.zip -d /opt \
    && ln -s /opt/chrome-linux64/chrome /usr/local/bin/chrome \
    && rm /tmp/chrome-linux64.zip

# Install latest chromedriver
RUN CHROMEDRIVER_URL=$(curl -s https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json | jq -r '.channels.Stable.downloads.chromedriver[] | select(.platform == "linux64") | .url') \
    && curl -sSLf --retry 3 --output /tmp/chromedriver-linux64.zip "$CHROMEDRIVER_URL" \
    && unzip -o /tmp/chromedriver-linux64.zip -d /tmp \
    && rm -rf /tmp/chromedriver-linux64.zip \
    && mv -f /tmp/chromedriver-linux64/chromedriver "/usr/local/bin/chromedriver" \
    && chmod +x "/usr/local/bin/chromedriver"

According to https://chromedriver.chromium.org/downloads/version-selection as of version 115 Google has changed the release process for Chrome and Chromedriver. There are multiple JSON endpoints that you can probe for latest stable version of both Chrome and Chromedriver.

This answer is inspired by the answer of Dr Nic except that it uses the endpoint for getting the latest (stable) versions.

Dmitry Shvedov
  • 3,169
  • 4
  • 39
  • 51
  • Thank you very much for all your comments. I tried the below in my Dockerfile, seems to work fine. `RUN google-chrome --version | grep -oE "[0-9]{1,10}.[0-9]{1,10}.[0-9]{1,10}.[0-9]{1,10}" > /tmp/chromebrowser-main-version.txt` `RUN wget -N https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$(cat /tmp/chromebrowser-main-version.txt)/linux64/chromedriver-linux64.zip -P ~/` `RUN unzip ~/chromedriver-linux64.zip -d ~/` `RUN rm ~/chromedriver-linux64.zip` `RUN mv -f ~/chromedriver-linux64 /usr/local/bin/chromedriver` – Ram Aug 24 '23 at 12:37
  • I am having trouble installing chrome again. The below command. `RUN CHROME_URL=$(curl -s https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json | jq -r '.channels.Stable.downloads.chrome[] | select(.platform == "linux64") | .url') \ && curl -sSLf --retry 3 --output /tmp/chrome-linux64.zip "$CHROME_URL" \ && unzip /tmp/chrome-linux64.zip -d /opt \ && ln -s /opt/chrome-linux64/chrome /usr/local/bin/chrome \ && rm /tmp/chrome-linux64.zip` getting error /bin/sh: 1: jq: not found – Ram Sep 01 '23 at 13:28
  • Just to add to this. I printed the current version of chrome in linux `RUN apt-get -y install -y google-chrome-stable RUN google-chrome --version` and its printing 116.0.5845.140. But this version according to https://googlechromelabs.github.io/chrome-for-testing is an upcoming version. So I am bit confused why the chrome version in linux is showing the upcoming ver and not the stable verion. Any help much appreciated. – Ram Sep 01 '23 at 15:15
  • Yeah, you need to have the `jq` utility installed. Not sure what Linux flavour that image is based on. If it's debian-based, you need to have `RUN apt-get install jq` somewhere before installing Chrome. – Dmitry Shvedov Sep 02 '23 at 15:55
  • You're printing current version that's in your linux repo. The installation method that I present in the answer does not depend on the repo. The versions come from here: https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json . At this moment the one mentioned there is `116.0.5845.96`, like you'd expect. – Dmitry Shvedov Sep 02 '23 at 15:58
0

You need to find a driver_version in latest_release_url, which is available at chrome-for-testing#json-api-endpoints, then specified the latest_release_url and driver_version parameters.

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
...
...
options = Options()
options.add_argument("--no-sandbox")
options.add_argument('--headless=new')
options.add_argument("--disable-gpu")

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager(
            latest_release_url='https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json',
            driver_version='116.0.5845.96').install()), options=options)

In this case, I use last-known-good-versions-with-downloads.json; and pick version 116.0.5845.96. It works.

0

I'd simply recommend downgrading Chrome to 114 (This worked for me while configuring Jibri)

wget http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_114.0.5735.198-1_amd64.deb

sudo dpkg -i google-chrome-stable_114.0.5735.198-1_amd64.deb