5

I wonder if anyone can help me with this error that I'm getting.

I want to use Selenium to monitor a web page on a (headless) Raspberry Pi 4 using Python. I have installed Selenium and installed the correct versions of Chromedriver that needs to work with AMRHF for Raspberry PIs;

Here are the versions of what i'm using:

chromium-browser:  Chromium 86.0.4240.197
chromedriver: 86.0.4240.197
python 3.7
selenium-3.141.0

Here is my script:

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver')

driver.get("https://www.google.com")

driver.close()

Here is the Traceback error I get:

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver')
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

I've spent half a day on this trying different things and I'm lost. Can anyone help? Thanks!

bazmattaz
  • 123
  • 2
  • 9
  • Hi there, I'm running Raspbian GNU/Linux 10 (buster). I think I installed chromedriver using PIP. Do you think there is a problem with the chromedriver? maybe i shoudl reinstall? – bazmattaz Jan 07 '21 at 19:08

1 Answers1

6

Install chromedriver using apt install:

sudo apt install chromium-chromedriver

If Chromium already installed check version, both Chromium and chromedriver should be same version.

Install Selenium using pip:

pip3 install selenium 

Try to give permissions to already installed chromedriver:

sudo chmod 755 /usr/lib/chromium-browser/chromedriver

Raspberry with Ubuntu 20.04 Server enter image description here

Remove already installed Chromium source and reinstall with chromedriver:

sudo apt purge --remove chromium-browser -y
sudo apt autoremove && sudo apt autoclean -y
sudo apt install chromium-chromedriver
Sers
  • 12,047
  • 2
  • 12
  • 31
  • Thanks for this. When I tried to give permissions it said "operation not permitted". I then used "sudo chmod" and that worked fine. I decided to run my script with "sudo python3 test.py" instead of the usual "python3 script.py" and I get; `Traceback (most recent call last): File "test.py", line 1, in from selenium import webdriver ModuleNotFoundError: No module named 'selenium'` – bazmattaz Jan 07 '21 at 19:13
  • First install `sudo apt install chromium-chromedriver` chromedriver. Then install selenium: `pip3 install selenium`. That should work – Sers Jan 07 '21 at 19:30
  • Hey thanks for getting back to me @sers. When I ran them it simply said that they were both already installed. So unfortunately I get the same error at the moment that i was getting before. `sudo apt install chromium-chromedriver chromium-chromedriver is already the newest version (86.0.4240.197-rpt1).` `pip3 install selenium Requirement already satisfied: selenium in /home/pi/.local/lib/python3.7/site-packages (3.141.0) Requirement already satisfied: urllib3 in /usr/lib/python3/dist-packages (from selenium) (1.24.1)` – bazmattaz Jan 07 '21 at 20:29
  • I have Raspberry with Ubuntu 20.04 Server installed and there's no issue. Did you install Chrome separate? My version installed `sudo apt install chromium-chromedriver` is 87.0.4280.88. Installation of `chromium-chromedriver` installing Chromium also, no need to install it separately. Your issue is probably related to uncompatibility of driver and Chromium versions – Sers Jan 07 '21 at 20:53
  • Thanks for your help @sers but unfortunately that didnt work either. Were you running on ubuntu? As i'm on running on a Raspberry Pi - so maybe that's the difference? – bazmattaz Jan 07 '21 at 22:41
  • Thank you @Sers – meta4 Jun 11 '21 at 23:01