Setup Selenium on Ubuntu 18.04

Install

docker run --rm -it ubuntu:20.04 bash
apt update && apt upgrade -y

# install dependencies
apt install -y curl gpg python3-pip python3-venv unzip

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

# install chromedriver
# see: https://sites.google.com/a/chromium.org/chromedriver/downloads
apt show google-chrome-stable | sed -nre '/^Version: /{s/^[^:]+: //;p}'
cd /tmp
wget https://chromedriver.storage.googleapis.com/88.0.4324.96/chromedriver_linux64.zip
unzip /tmp/chromedriver_linux64.zip
mv chromedriver /usr/bin/chromedriver
chown root: /usr/bin/chromedriver
chmod 755 /usr/bin/chromedriver

# install selenium client (python)
cd ~
python3.8 -m venv venv
. venv/bin/activate
pip install selenium

First Usage

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.binary_location = '/usr/bin/google-chrome'

chrome_driver = '/usr/bin/chromedriver'

driver = webdriver.Chrome(executable_path=chrome_driver, chrome_options=chrome_options)
driver.get('https://box.attie.co.uk/')
driver.save_screenshot('/tmp/screenshot.png')

assert "my box..." in driver.page_source
driver.close()