skip to Main Content

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)

2

Answers


  1. 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
    
    Login or Signup to reply.
  2. 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)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search