'RPi 4 + Selenium + Firefox + Geckodriver: errors when running
I am trying to run selenium 4.1.0 through firefox on my raspberry pi 4 running raspbian/raspiOS (can't use chromium. been there tried that.).
I am using geckodriver 0.23.0 (latest that has arm7 download). My firefox version is 78.15.0esr (from about:support), which according to this should be supported by that driver version, I think.
In case it means anything, I installed firefox through sudo apt install firefox-esr.
My (relevant) python3 code is as follows:
from selenium import webdriver
WINDOW_SIZE = '1280,720'
options = webdriver.FirefoxOptions()
options.add_argument('--headless')
options.add_argument('--window-size=%s' % WINDOW_SIZE)
driver = webdriver.Firefox(webdriver.FirefoxProfile('/home/pi/.mozilla/firefox/kvz2n0sv.default-esr'), options=options, executable_path='/usr/local/bin/geckodriver')
driver.get('url')
# Do stuff
driver.quit()
When I run this (both with the profile open and closed), I get the following error:
selenium.common.exceptions.WebDriverException: Message: Service /usr/local/bin/geckodriver unexpectedly exited. Status code was: 1
The full output (including some irrelevant stuff) is:
enrichment.py:26: DeprecationWarning: firefox_profile has been deprecated, please use an Options object
driver = webdriver.Firefox(webdriver.FirefoxProfile('/home/pi/.mozilla/firefox/kvz2n0sv.default-esr'), executable_path='/usr/local/bin/geckodriver', options=options)
enrichment.py:26: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Firefox(webdriver.FirefoxProfile('/home/pi/.mozilla/firefox/kvz2n0sv.default-esr'), executable_path='/usr/local/bin/geckodriver', options=options)
enrichment.py:26: DeprecationWarning: firefox_profile has been deprecated, please pass in an Options object
driver = webdriver.Firefox(webdriver.FirefoxProfile('/home/pi/.mozilla/firefox/kvz2n0sv.default-esr'), executable_path='/usr/local/bin/geckodriver', options=options)
Traceback (most recent call last):
File "enrichment.py", line 26, in <module>
driver = webdriver.Firefox(webdriver.FirefoxProfile('/home/pi/.mozilla/firefox/kvz2n0sv.default-esr'), executable_path='/usr/local/bin/geckodriver', options=options)
File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
self.service.start()
File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 112, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /usr/local/bin/geckodriver unexpectedly exited. Status code was: 1
Thanks for the help.
Solution 1:[1]
You can build your own geckodriver and use it with firefox97.0. but a simpler way is to install the corresponding file directly using the following command
sudo apt install firefox=97.0+build2-0ubuntu0.20.04.1
sudo apt install firefox-geckodriver=97.0+build2-0ubuntu0.20.04.1
Before installing, I think you should clean up the Firefox and geckodriver installed before.
Then you can use it like this
from selenium import webdriver
WINDOW_SIZE = '1280,720'
options = webdriver.FirefoxOptions()
options.add_argument('--headless')
options.add_argument('--window-size=%s' % WINDOW_SIZE)
driver = webdriver.Firefox(options=options)
driver.get('url')
driver.close()
It works on my raspberrypi4B Ubuntu 20.04.4 LTS
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | PandaCN |
