Is there a known working configuration for using Selenium on linux-arm64?
Asked Answered
S

6

6

I wrote a quick program that simply opens and closes a website using Firefox at set intervals. It runs perfectly on my Intel Mac OS Ventura. I intended to keep it running on a Raspberry Pi, but I cannot find a combination of versions of Selenium, geckodriver or chromedriver, and Firefox or Chromium that will run on it.

The Mac has Selenium 4.11.2, geckodriver v0.33.0, and Firefox 115.0.3 working. The Raspberry Pi has Ubuntu 22.04.3 LTS. I found out here, https://github.com/SeleniumHQ/selenium/issues/11599, that Selenium Manager doesn't work on linux-arm64, and the Raspberry Pi uses linux-arm64. I was getting errors even when I tried to code in the path to the driver, with Selenium logging that it couldn't find a driver, even while it was also in PATH. It looks like the developers say in the conversation above that the built in Selenium Manager driver manager causes errors like these. Selenium Manager was introduced in Selenium 4.6, so I rolled back to Selenium 4.5, altered my code for that version, tried to run it, and got different errors that seemed to be about incompatibility issues between the driver and the version of Firefox. I tried different combinations of them with no success. Then I decided to try Chrome instead. Google does not provide a chromedriver build for linux-arm64, so I tried to use different versions found here, https://github.com/electron/electron/releases, as well as trying to roll back Chromium. I was able to at least launch the Chromium browser with the program, which is more success than I had with Firefox, but I could not get it fully working. All along the whole process I read many answers to Selenium problems on Stack Overflow, but nothing has helped.

Here is the code that runs fine on Mac with the configuration above:

import datetime, logging, time
from selenium import webdriver

logger = logging.getLogger('selenium')
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler("handler.log")
logger.addHandler(handler)
logging.getLogger('selenium.webdriver.remote').setLevel(logging.DEBUG)
logging.getLogger('selenium.webdriver.common').setLevel(logging.DEBUG)
logging.basicConfig(filename="program.log", level=logging.INFO)
timeStarted = datetime.datetime.now()
logging.info(
    timeStarted.strftime("%m/%d/%Y, %H:%M:%S")
    + "   started on https://google.com"
)
# Program starts here
while True:
    timeOfRequest = datetime.datetime.now()
    try:
        browser = webdriver.Firefox()
        browser.get("https://google.com")
        logging.info(
            timeOfRequest.strftime("%m/%d/%Y, %H:%M:%S")
            + "   Success"
        )
    except:
        logging.exception(
            timeOfRequest.strftime("%m/%d/%Y, %H:%M:%S") + "   Something went wrong"
        )
    time.sleep(810)
    browser.quit()
    time.sleep(30)
Shrike answered 8/8, 2023 at 8:48 Comment(0)
K
6

Here is what I got after spending a whole evening trying to solve this problem:

To use Selenium on linux-arm64, we'll need to obtain three old Debian packages:

Below is a step-by-step guide.

Installation

Download the packages

To fetch the necessary Debian packages directly from the launchpad, we can use the wget command.

# Fetch chromium-codecs-ffmpeg-extra
wget http://launchpadlibrarian.net/660838579/chromium-codecs-ffmpeg-extra_112.0.5615.49-0ubuntu0.18.04.1_arm64.deb

# Fetch chromium-browser
wget http://launchpadlibrarian.net/660838574/chromium-browser_112.0.5615.49-0ubuntu0.18.04.1_arm64.deb

# Fetch chromium-chromedriver
wget http://launchpadlibrarian.net/660838578/chromium-chromedriver_112.0.5615.49-0ubuntu0.18.04.1_arm64.deb

Once ready, can install them using gdebi-core, which will handle the dependencies.

Install gdebi-core

sudo apt-get install gdebi-core

Install the Debian packages

sudo gdebi chromium-codecs-ffmpeg-extra_112.0.5615.49-0ubuntu0.18.04.1_arm64.deb
sudo gdebi chromium-browser_112.0.5615.49-0ubuntu0.18.04.1_arm64.deb
sudo gdebi chromium-chromedriver_112.0.5615.49-0ubuntu0.18.04.1_arm64.deb

After following these steps, should have a working configuration of Selenium with ChromeDriver on linux-arm64.

Verify Installation

chromium-browser --version

the output should be like Chromium 112.0.5615.49 Built on Ubuntu , running on Ubuntu 22.04

To further test the installation, save the following script as test.py. Note that the arguments provided for options are essential:

from selenium import webdriver

# Initialize the Chrome WebDriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
# options.add_argument('--disable-dev-shm-usage')
# options.add_argument('--remote-debugging-port=9222') 


driver = webdriver.Chrome(options=options)

# Retrieve the capabilities
capabilities = driver.capabilities

# For Chrome:
if 'browserName' in capabilities and capabilities['browserName'] == 'chrome':
    browser_version = capabilities.get('browserVersion', 'Unknown')
    chromedriver_version = capabilities.get('chrome', {}).get('chromedriverVersion', 'Unknown').split(' ')[0]
    print(f"Browser Name: Chrome")
    print(f"Browser Version: {browser_version}")
    print(f"ChromeDriver Version: {chromedriver_version}")

# Close the driver
driver.quit()

Executing python test.py should yield:

Browser Name: Chrome
Browser Version: 112.0.5615.49
ChromeDriver Version: 112.0.5615.49
Kiser answered 25/8, 2023 at 15:38 Comment(2)
A thousand thumbs-up my friend, really appreciated! After I wasted couple of hours on this I thought this kind of setup was not even possible. This works very well.Hauteur
@MartinVysny Thank you for the kind words! I'm glad to know that the solution works for you!Kiser
D
6

Selenium Manager doesn't work on linux-arm64, Yes because the arch is x86 for the selenium-manager, wondering why the binary has been built not for arm64 making troubles. I figure it out using the file command on selenium-manager binary (both python and node suffers from this wrong arch - nodejs selenium fails ) selenium-manager: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped I found a way to solve this by installing :

sudo apt install binfmt-support qemu qemu-user-static

assuming you download the geckodriver
https://github.com/mozilla/geckodriver/releases/download/v0.33.0/geckodriver-v0.33.0-linux-aarch64.tar.gz and declare its directory you unpacked it in ~/.local/bin/ declared in you .bashrc or .profile in the PATH

a working starting python code I use is

from selenium import webdriver
from selenium.webdriver.firefox.options import Options 
options = Options()
options.binary_location = r'/usr/bin/firefox-esr'
from selenium.webdriver.firefox.service import Service
service = Service('/home/pi/.local/bin/geckodriver')
driver = webdriver.Firefox(options=options, service=service)
Dustindustman answered 13/9, 2023 at 16:52 Comment(1)
Works !!! System: aarch64 debian_bullseye geckodriver: v0.33.0-linux-aarch64 Firefox: Mozilla Firefox 115.5.0esrTorietorii
H
1

Playwright is capable of downloading both Chromium and Firefox, with appropriate drivers, automatically for Linux arm64. If you can, please consider switching to Playwright instead, it's much more programmer-friendly than Selenium.

EDIT: This post is not meant to be a flamewar. I have nothing but respect for answers above which I find highly valuable. However, Playwright doesn't use the flawed concept of drivers but instead accesses the browser over a standardized Firefox CDP/Chrome DevTools Protocol. It's also capable of downloading the browsers itself, including Chromium & Firefox for Linux-arm64 (!). The API is also arguably better designed than Selenium.

I've experienced a lot of pain fixing Selenium Drivers after browser update in the past; I'll personally never use Selenium again. Unless you have to stick with Selenium I'd recommend to go with Playwright instead.

Hauteur answered 16/5, 2024 at 15:20 Comment(0)
J
0

I think the problem was mainly because Google does not build Chrome for ARM on Linux. If you are in an arm64-based machine, and you try to pull the official image: selenium/standalone-chrome you will see that there is “no matching manifest for linux/arm64/v8 in the manifest list entries”. Thus, for those interested in an implementation with arm64 (e.g., MACs with M1, M2, Mx CPUs), the option so far is to use Chromium instead of Chrome. If you don’t want to play around on your own, a good forked solution provided by some guys of the Selenium Community can be found at: https://github.com/seleniumhq-community/docker-seleniarm. They provide images for both arm64 and amd86-64 linuxes. Furthermore, there is more recent news on that. The guys of the official Docker Selenium project, have finally decided to merge the seleniarm fork into the main project. See the announcement on Thursday, May 23, 2024 here. From image tag releases 4.21.0 onwards, both architectures (x86_64 - amd64 and aarch64 - arm64/armv8) are supported by Docker Selenium. Both of them are based on Ubuntu LTS. Of course, for the and aarch64 - arm64/armv8, only the binaries for the Chromium browser are used.

Jerilynjeritah answered 3/6, 2024 at 6:1 Comment(0)
O
0

I was also able to run the Selenium driver on Linux Aarch64 using Firefox Nightly and Gecko Driver for Aarch64.

from selenium import webdriver
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.firefox.service import Service

service = Service(executable_path='/usr/bin/geckodriver')
options = FirefoxOptions()
options.add_argument("--headless")
driver = webdriver.Firefox(service=service, options=options)

I am running in headless mode to use it on a server.

Outrider answered 15/8, 2024 at 20:17 Comment(0)
M
0

Please do NOT use the top rated answer since it will break your system's packages. Installing random .deb files from different distros is bad practice. See https://wiki.debian.org/DontBreakDebian for why.

On Ubuntu and Debian, you do not need to mess with older versions of packages, since there is already an ARM64 version of chromedriver available.

On Ubuntu:

sudo apt install chromium-chromedriver

On Debian:

sudo apt install chromium-driver

In your Python code, you may manually specify the chromedriver path. For example:

import shutil

import selenium.common.exceptions
from selenium import webdriver

#you may customize these options based on your own needs
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument("enable-automation")
options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-browser-side-navigation")
options.add_argument("--disable-gpu")

try:
  #in case we are on x86_64 we do not need the chromeservice workaround,
  #so try the normal way first
  browser = webdriver.Chrome(options=options)
except selenium.common.exceptions.NoSuchDriverException:
  chromedriver_path = shutil.which("chromedriver") #/usr/bin/chromedriver
  service = webdriver.ChromeService(executable_path=chromedriver_path)
  browser = webdriver.Chrome(options=options, service=service)

This worked for me on Ubuntu 24.04 on ARM64 inside WSL2.

Melissa answered 3/9, 2024 at 23:0 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.