Setup Selenium on Ubuntu 18.04

Install

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

# install dependencies
apt install -y curl gpg python3-pip virtualenv 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
cd /tmp
wget https://chromedriver.storage.googleapis.com/76.0.3809.68/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)
virtualenv -p python3.6 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/')

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