Install WebDriver Chrome or Firefox for Selenium for automated testing web application

ChromeDriver Mac

pip3 install chromedriver-binary-auto
from selenium import webdriver
import chromedriver_binary  # Adds chromedriver binary to path

driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title

ChromeDriver Ubuntu

The default browser included with Ubuntu is incompatible with the driver. To ensure compatibility, you must install the official version. Or try to use pip3 install chromedriver-binary-auto.

 

This is not working.

sudo apt-get install chromium-browser



Install Chrome browser new version.. 


chromium-browser --version

/usr/bin/chromium-browser: 12: xdg-settings: not found

Chromium 120.0.6099.71 snap



Install chrome browser

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb


sudo dpkg -i google-chrome-stable_current_amd64.deb


sudo apt-get install -f


google-chrome --version

Google Chrome 120.0.6099.71


https://googlechromelabs.github.io/chrome-for-testing/#stable 


https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/120.0.6099.71/linux64/chromedriver-linux64.zip


wget https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/120.0.6099.71/linux64/chromedriver-linux64.zip


unzip


mv chromedriver /usr/local/bin/


chromedriver --version

ChromeDriver 120.0.6099.71 (9729082fe6174c0a371fc66501f5efc5d69d3d2b-refs/branch-heads/6099_56@{#13})



/usr/local/bin/chromedriver

Starting ChromeDriver 120.0.6099.71 (9729082fe6174c0a371fc66501f5efc5d69d3d2b-refs/branch-heads/6099_56@{#13}) on port 9515

Only local connections are allowed.

Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.

ChromeDriver was started successfully.



Test it minimal script 


from selenium import webdriver

from selenium.webdriver.chrome.service import Service

from selenium.webdriver.chrome.options import Options


options = Options()

options.add_argument("--headless")

options.add_argument("--no-sandbox")

options.add_argument("--disable-dev-shm-usage")

options.add_argument("--disable-gpu")

options.add_argument("window-size=1920,1080")


service = Service('/usr/local/bin/chromedriver')

driver = webdriver.Chrome(service=service, options=options)

 

 

 

So if you get versions conflict. 

Troubleshooting SessionNotCreatedException

The SessionNotCreatedException with the message "session not created: DevToolsActivePort file doesn't exist" typically occurs when trying to run Chrome or Chromium in headless mode using Selenium WebDriver. This error can be caused by several factors related to how Chrome is initialized. Here are some steps to troubleshoot and resolve this issue:

  1. Update Chrome and ChromeDriver:
    • Ensure both Google Chrome and ChromeDriver are updated to the latest versions. Version incompatibility between the two can often cause this issue.
  2. Correctly Configure Chrome Options:
    • When running Chrome in headless mode, certain Chrome options need to be set. The most common options to resolve this issue are:
      
      from selenium import webdriver
      from selenium.webdriver.chrome.options import Options
      
      options = Options()
      options.add_argument("--headless")
      options.add_argument("--no-sandbox")
      options.add_argument("--disable-dev-shm-usage")
      options.add_argument("--disable-gpu")
      # Add window-size if required
      options.add_argument("window-size=1920,1080")
                          
  3. Check the Environment:
    • This error is more common in containerized environments (like Docker) or when there are restrictions on the system (like in some CI environments). The --no-sandbox and --disable-dev-shm-usage flags are particularly important in these cases.
  4. Verify the ChromeDriver Path:
    • Make sure the path to chromedriver is correctly specified in your Selenium script, especially if it's not in your system's PATH.
  5. Permissions:
    • Ensure that the chromedriver executable has the correct permissions. You might need to set execute permissions using chmod +x /path/to/chromedriver.
  6. Check for Conflicting Processes:
    • Sometimes, existing Chrome processes can interfere with the new session creation. Ensure that no lingering Chrome processes are running before starting a new Selenium session.
  7. Sample Selenium Script:
    • Here's an example of how your Selenium script might look with these options:
      
      from selenium import webdriver
      from selenium.webdriver.chrome.service import Service
      from selenium.webdriver.chrome.options import Options
      
      options = Options()
      options.add_argument("--headless")
      options.add_argument("--no-sandbox")
      options.add_argument("--disable-dev-shm-usage")
      options.add_argument("--disable-gpu")
      options.add_argument("window-size=1920,1080")
      
      service = Service('/path/to/chromedriver')
      driver = webdriver.Chrome(service=service, options=options)
                          
  8. Running as Root User (Not Recommended):
    • If you're running the script as a root user (especially in Docker or similar environments), the --no-sandbox argument becomes necessary. However, running a browser as a root user is generally not recommended due to security concerns.

If you've followed these steps and still encounter the issue, please provide more context or additional error messages for further troubleshooting.

 






 

Old version installs... 

Firefox


Installation for automated testing


sudo apt-get update


apt-get install -y unzip openjdk-8-jre-headless xvfb libxi6 libgconf-2-4

apt-get install firefox

Pip install selenium

Sometimes you can get some exceptions

Selenium “Unable to find a matching set of capabilities” despite driver being in /usr/local/bin

Or

selenium.common.exceptions.WebDriverException: Message: Unable to find a matching set of capabilities




Updating Firefox and Selenium solved it for me. I don't pretend to have an explanation for the root cause however.


Updated Firefox 48 → 53


Updated to Selenium 3.4.1




https://pypi.org/project/selenium/

https://github.com/mozilla/geckodriver/releases

https://chromedriver.chromium.org/downloads  



Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line


Firefox browser has installed?


apt-get install firefox


Script example for chrome WebDriver automated installation on Ubuntu


#!/usr/bin/env bash
# https://developers.supportbee.com/blog/setting-up-cucumber-to-run-with-Chrome-on-Linux/

# https://gist.github.com/curtismcmullan/7be1a8c1c841a9d8db2c

# http://stackoverflow.com/questions/10792403/how-do-i-get-chrome-working-with-selenium-using-php-webdriver

# http://stackoverflow.com/questions/26133486/how-to-specify-binary-path-for-remote-chromedriver-in-codeception

# http://stackoverflow.com/questions/40262682/how-to-run-selenium-3-x-with-chrome-driver-through-terminal

# http://askubuntu.com/questions/760085/how-do-you-install-google-chrome-on-ubuntu-16-04

# Versions

CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`
SELENIUM_STANDALONE_VERSION=3.4.0
SELENIUM_SUBDIR=$(echo "$SELENIUM_STANDALONE_VERSION" | cut -d"." -f-2)


Remove existing downloads and binaries so we can start from scratch.

sudo apt-get remove google-chrome-stable
rm ~/selenium-server-standalone-*.jar
rm ~/chromedriver_linux64.zip
sudo rm /usr/local/bin/chromedriver
sudo rm /usr/local/bin/selenium-server-standalone.jar
 

Install dependencies


sudo apt-get update
sudo apt-get install -y unzip openjdk-8-jre-headless xvfb libxi6 libgconf-2-4


Install Chrome


sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
sudo echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
sudo apt-get -y update
sudo apt-get -y install google-chrome-stable


Install ChromeDriver

wget -N http://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -P ~/

unzip ~/chromedriver_linux64.zip -d ~/

rm ~/chromedriver_linux64.zip

sudo mv -f ~/chromedriver /usr/local/bin/chromedriver

sudo chown root:root /usr/local/bin/chromedriver

sudo chmod 0755 /usr/local/bin/chromedriver

# Install Selenium.

wget -N http://selenium-release.storage.googleapis.com/$SELENIUM_SUBDIR/selenium-server-standalone-$SELENIUM_STANDALONE_VERSION.jar -P ~/

sudo mv -f ~/selenium-server-standalone-$SELENIUM_STANDALONE_VERSION.jar /usr/local/bin/selenium-server-standalone.jar

sudo chown root:root /usr/local/bin/selenium-server-standalone.jar

sudo chmod 0755 /usr/local/bin/selenium-server-standalone.jar








Downgrading Google Chrome & Matching the Right ChromeDriver

When you automate browser workflows with Selenium or undetected-chromedriver, a version mismatch between Chrome and ChromeDriver will throw errors like:

SessionNotCreatedException: This version of ChromeDriver only supports Chrome version 137
Current browser version is 114.0.5735.90

To avoid this, follow these steps:

1. Determine Your Installed Chrome Version

On Debian/Ubuntu run:

google-chrome --version
# or, if you’ve already downgraded to chromium:
chromium-browser --version

Let’s say it outputs:

Google Chrome 114.0.5735.90

2. Download an Older Chrome .deb

Google’s official repos only serve the latest. For archives, use a mirror like UChicago’s:

https://mirror.cs.uchicago.edu/google-chrome/pool/main/g/google-chrome-stable/

Browse that directory to find the exact google-chrome-stable_-1_amd64.deb you need—for example:

wget https://mirror.cs.uchicago.edu/google-chrome/pool/main/g/google-chrome-stable/google-chrome-stable_114.0.5735.90-1_amd64.deb
sudo dpkg -i google-chrome-stable_114.0.5735.90-1_amd64.deb
sudo apt-get -f install   # to pull in any dependencies

Verify:

google-chrome --version
# → Google Chrome 114.0.5735.90

3. Find the Matching ChromeDriver

ChromeDriver releases are keyed by Chrome’s major version (the first number). For Chrome 114.0.5735.90, query:

# Fetch the latest driver for Chrome 114.x:
LATEST=$(wget -qO- https://chromedriver.storage.googleapis.com/LATEST_RELEASE_114)
echo "ChromeDriver version → $LATEST"
# → 114.0.5735.90

Then download the Linux binary:

wget https://chromedriver.storage.googleapis.com/$LATEST/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/local/bin/
sudo chmod +x /usr/local/bin/chromedriver

Verify:

chromedriver --version
# → ChromeDriver 114.0.5735.90

4. Automate Driver Version Resolution

In your Python scripts, you can automate this lookup so they always match:

import requests, zipfile, io, subprocess

def install_matching_chromedriver(chrome_major: str):
    # 1. Query LATEST_RELEASE_
    url = f"https://chromedriver.storage.googleapis.com/LATEST_RELEASE_{chrome_major}"
    version = requests.get(url).text.strip()

    # 2. Download & unpack
    zip_url = f"https://chromedriver.storage.googleapis.com/{version}/chromedriver_linux64.zip"
    resp = requests.get(zip_url)
    with zipfile.ZipFile(io.BytesIO(resp.content)) as z:
        z.extract("chromedriver", "/usr/local/bin/")

    # 3. Permissions
    subprocess.run(["chmod", "+x", "/usr/local/bin/chromedriver"], check=True)
    print("Installed ChromeDriver", version)

if __name__ == "__main__":
    # detect current Chrome version:
    out = subprocess.check_output(["google-chrome", "--version"]).decode()
    major = out.split()[2].split(".")[0]
    install_matching_chromedriver(major)

5. Tips & Gotchas

  • Binary paths: Make sure your script’s options.binary_location matches where your browser lives (e.g. /usr/bin/google-chrome, /usr/bin/chromium-browser, or /opt/google/chrome/google-chrome).
  • Headless flags: Chrome’s headless mode changed in v109; use --headless=new for ≥v109.
  • System updates: Pin your Chrome package to prevent accidental upgrades (apt-mark hold google-chrome-stable).
  • Alternative mirrors: If UChicago is slow, other mirrors exist under the same directory structure (e.g. TU-Berlin, Stanford, etc.).

By following these steps, you’ll keep your browser and driver perfectly aligned and avoid those dreaded SessionNotCreatedException errors.

vim test2immoweb.py

Working verions is in root of demo server.
root@demo-web:/home/admin/leads_manager# vim test2immoweb.py
I commit it in /onlinesolutionsgroup/bauwens.git

Comments