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

 Chrome

The default browser included with Ubuntu is incompatible with the driver. To ensure compatibility, you must install the official version


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








Comments