1

I have a Python script running on an EC2 instance (Ubuntu) on AWS. It uses selenium. It was working perfectly for weeks, and then all of the sudden, today, it stopped working with the following error:

selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 79

Here is my Python script, which I'm running on Ubuntu:

#install dependencies
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import ElementNotVisibleException
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

#Set up chromedriver
options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--window-size=1420,1080')
options.add_argument('--headless')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--disable-gpu')
options.add_argument("--disable-notifications")

driver = webdriver.Chrome(chrome_options=options)

What is odd is that chromedriver and chromium-browser appear to be compatible.

Upon running chromedriver -v I see the version is:

ChromeDriver 79.0.3945.79 (29f75ce3f42b007bd80361b0dfcfee3a13ff90b8-refs/branch-heads/3945@{#916})

And, running chromium-browser --version I get:

Chromium 79.0.3945.79 Built on Ubuntu , running on Ubuntu 18.04

Upon running chromium-browser -v I see :

(chromium-browser:2901): Gtk-WARNING **: 17:28:14.613: cannot open display: 

Two questions I'm hoping to answer :

  1. How could work for weeks, and then all of the sudden, chromedriver and Chrome decide not to cooperate with each other? Could it be that either chromedriver or chrome was updated without the other being updated? I did not change anything, with the exception of updating the time from which the script was run from crontab.

  2. Why is this error happening when my chromedriver and Chrome browser are the exact same version? It was an extremely long process to get chromedriver to work with Chrome (headless) on Ubuntu and I'd like to "set it and forget it" if possible. I am looking for a way to better understand this problem so I can avoid it happening again and again.

halfer
  • 19,824
  • 17
  • 99
  • 186
DiamondJoe12
  • 1,879
  • 7
  • 33
  • 81

2 Answers2

1

By default, webdriver.Chrome runs /usr/bin/google-chrome if available, not chromium-browser (see Default location of ChromeDriver binary and Chrome binary on windows 7). Check google-chrome --version.

Matt Zimmerman
  • 529
  • 5
  • 10
  • Thank you Matt. google-chrome --version reveals: Google Chrome 78.0.3904.70 Do I need to update it in ubuntu? – DiamondJoe12 Dec 22 '19 at 17:22
  • Debanjan, using options.binary_location='/path/to/chromium-browser.exe' did not work, but using options.binary_location='/path/to/chromium-browser' worked. – DiamondJoe12 Dec 23 '19 at 20:29
  • @DiamondJoe12 Yes, you would need to either update Chrome or configure ChromeDriver to use Chromium instead. It sounds like the latter worked for you. Could you accept this answer as the solution to your issue? – Matt Zimmerman Dec 23 '19 at 23:12
  • 1
    Matt - I will upvote your comment, but the other answer provided here actually was able to solve this. Thank you for your help! – DiamondJoe12 Dec 24 '19 at 16:23
1

This error message...

selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 79

...implies that the ChromeDriver v79 was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session where the browser version was other then v79.x.


Your main issue is the incompatibility between the version of the binaries you are using as follows:

Supports Chrome v79

  • You are using chromium-browser v79.0.3945.79 browser.
  • ChromeDriver supports google-chrome when installed at the default location with respect to the underlying os:

Chrome_binary_expected_location

1For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.


Solution

There are two solutions:

  • Either you upgrade google-chrome installed at the default location to current Chrome Version 79.0 level. (as per ChromeDriver v79.0 release notes)
  • Or you can override the default Chrome binary location i.e. /usr/bin/google-chrome with the chromium-browser binary location following the documentation Using a Chrome executable in a non-standard location as follows:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    options = Options()
    options.binary_location='/path/to/chromium-browser.exe'
    driver = webdriver.Chrome(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe', options=options)
    driver.get('http://google.com/')
    

You can find a detailed discussion in How to run a Chromium Browser with Selenium?

  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your @Test as non-root user.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

Reference

You can find a relevant detailed discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you. Where is my chromium-browser.exe? My chromium-browser is in /usr/bin, but when I do: options.binary_location='/usr/bin/chromium-browser.exe' the terminal reads Message: unknown error: no chrome binary at /usr/bin/chromium-browser.exe – DiamondJoe12 Dec 23 '19 at 20:25
  • @DiamondJoe12 You are on _Linux_ **Ubuntu**, you need to strip off the extension i.e. `.exe` part – undetected Selenium Dec 23 '19 at 20:29