Chrome Browser and Chromedriver on Ubuntu 20.04 With Python Selenium

Update the Linux VM

sudo apt update
sudo apt-get install -f

Download Chrome Browser

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
google-chrome --version

Download Chromedriver

You can download the Chromedriver from this location Download Chromedriver (opens new window)But you need the correct version, so remember which version of Chrome you have from step 1 above and download the correct Chromedriver.

In my case, I had version 114.xx.xxx.xx.xx. So I need to click on the version that supports 114 Install the correct Chromedriver

Click on the link, and it will take you to this page. Download the version that is best suited for your operating system, for me (Running Ubuntu 20.04 on Digital Ocean VPS) – the correct version is chromedriver_linux64.zip. You need to right-click on the link and copy the link.

wget https://chromedriver.storage.googleapis.com/114.0.4515.107/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/bin/chromedriver
sudo chown root:root /usr/bin/chromedriver
sudo chmod +x /usr/bin/chromedriver
chromedriver --url-base=/wd/hub

Testing with Python Selenium

sudo apt install python3
sudo apt install python3-venv
mkdir project_folder
cd project_folder
python3 -m venv myenv
source myenv/bin/activate
pip install selenium webdriver_manager

Create a main.py file

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(executable_path=r'/usr/bin/chromedriver')
op = webdriver.ChromeOptions()
op.add_argument('--headless')
op.add_argument('--no-sandbox')
op.add_argument('--disable-dev-shm-usage')
web = webdriver.Chrome(service=service, options=op)
web.get("https://google.com")
print(web.title)
web.quit()

Execute the file

python main.py

Leave a Comment