
Selenium Webdriver on Raspberry Pi Zero W.
TL;DR: Want to run Selenium-based browser automation on a Raspberry Pi Zero W? Firefox's geckodriver dropped ARM support in 2018, so it's a dead end. The solution is using the
chromium-chromedriverpackage that comes pre-built for ARM on Raspbian. This post covers the challenges of running browser automation on ARM hardware, the geckodriver vs chromedriver decision, and the full setup for headless Chromium with Selenium on Pi Zero W.
I have earlier written a post on how selenium can be used to automate browser based tasks.
See the post Selenium: Easy Web Automation with Python.
I recently bought a raspberry-pi, So wanted to add some tasks like making changes in router settings on raspberry-pi device.
What hardware does the Raspberry Pi Zero W use?
Raspberry-pi's raspbian OS is Linux based and its hardware is arm based. The Pi Zero W has a 1 GHz single-core ARMv6 CPU and 512 MB of RAM. That's small, so a headless browser is the only practical choice.
To check this on your raspberry-pi device run below command.
$ uname -a
Linux raspber 5.10.17+ #1414 Fri Apr 30 13:16:27 IST 2021 armv6l GNU/Linux
Why didn't geckodriver work on the Raspberry Pi?
I decided to go for firefox and geckodriver combination along with selenium. I thought this will be lightweight than chromium.
I did not find any suitable version of geckodriver for arm based machines. As geckodriver project has stopped supporting it since 2018.
I tried out some older versions of geckodriver shared online. But none of these work for me.
I also tried one geckodriver version built by someone following Mozilla's ARM build guide. And this as well didn't work.
I was getting error for OS mismatch with all geckodriver executables I tried.
Firefox - OSError: [Errno 8] Exec format error
How do I run Selenium on a Raspberry Pi Zero W?
I thought I have stuck dead-end and was about to keep this thing on the side. Then I found an article about the chromium-chromedriver package supported by the Raspbian project.
Run below command to install chromium-chromedriver package
$ sudo apt-get install chromium-chromedriver
This installs both chromium browser and chromedriver on raspberry-pi. Chromium is required for selenium to run a browser in headless mode and chromedriver to connect and control that browser.
"Selenium automates browsers. That's it!" — selenium.dev
This package works awesome on raspberry-pi, I was able to get the selenium tasks installed, and run them from CLI commands.
Later on I used ngrok to access these from anywhere, more about that in below post
See the post How to use ngrok to access your Raspberry Pi from anywhere.
What does a minimal headless script look like?
This is Selenium 4 syntax. I wrote the original setup on the Pi Zero W with an older Selenium and haven't re-tested this exact snippet on that device. Passing the system chromedriver path stops Selenium from trying to download a driver that may not exist for ARMv6:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
options = webdriver.ChromeOptions()
options.add_argument('--headless')
driver = webdriver.Chrome(service=Service('/usr/bin/chromedriver'), options=options)
driver.get('https://example.com')
print(driver.title)
driver.quit()
If the package isn't found, run apt-cache policy chromium-chromedriver first. Package names and availability differ between Raspberry Pi OS releases.
Frequently Asked Questions
Why do I get "Exec format error" on a Raspberry Pi?
The binary was built for a different CPU architecture. Many prebuilt ARM binaries target ARMv7 or ARM64, but the Pi Zero W runs ARMv6, so they won't start.
Do Chromium and chromedriver versions need to match?
Yes. chromedriver only works with the matching major Chromium version. Installing both from the same chromium-chromedriver package keeps them in sync.
How do I run Chromium headless from Python?
Create webdriver.ChromeOptions(), call options.add_argument('--headless'), and pass the options to webdriver.Chrome(options=options).