6

So I'm trying to run Selenium on my raspberry pi using Chromium and for some reason I can't get my python file to compile. I keep getting the following error:

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    driver = webdriver.Chrome(os.path.expanduser('/usr/bin/chromedriver.exe'))
  File "/usr/local/lib/python2.7/dist-packages/selenium-2.46.0-py2.7.egg/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium-2.46.0-py2.7.egg/selenium/webdriver/chrome/service.py", line 75, in start
os.path.basename(self.path), docs_msg)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

Here is the python code I'm trying to run:

from selenium import webdriver
import os

driver = webdriver.Chrome(os.path.expanduser('/usr/bin/chromedriver'))

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

driver.quit()

Any ideas?

Update

After removing the '.exe' at the end of chromedriver, it now produces the following error:

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    driver = webdriver.Chrome(os.path.expanduser('/usr/bin/chromedriver'))
  File "/usr/local/lib/python2.7/dist-packages/selenium-2.46.0-py2.7.egg/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium-2.46.0-py2.7.egg/selenium/webdriver/chrome/service.py", line 68, in start
self.service_args, env=env, stdout=PIPE, stderr=PIPE)
  File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
    raise child_exception
OSError: [Errno 8] Exec format error
Manny
  • 61
  • 1
  • 1
  • 4
  • You need to provide it with a `chromedriver` binary [for linux](http://chromedriver.storage.googleapis.com/index.html?path=2.16/), not `chromedriver.exe`. – alecxe Jul 02 '15 at 16:45
  • I took off the '.exe' at the end of the chromedriver file. That being said, I can assure you that I am using the binary specifically made for linux. – Manny Jul 02 '15 at 16:59
  • Removing the `.exe` from the end of the filename does not make it less windows executable. Follow the link I've provided, download the one for linux and use. – alecxe Jul 02 '15 at 18:02
  • Like I mentioned in my previous comment. I've already downloaded the chromedriver for linux. I've been using it this entire time. The only reason I had '.exe' at the end of the file was because I thought the entire filename was supposed to be written out completely. Sorry for the confusion. – Manny Jul 02 '15 at 18:08
  • Yeah, sorry for the confusion. I think these topics are related to the problem: https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=95322 and http://raspberrypi.stackexchange.com/questions/2029/chromedriver-and-selenium-webdriver-unable-to-connect-to-chromedriver-http. In short, this is about the arm architecture. – alecxe Jul 02 '15 at 18:12
  • 1
    From the command line, on the PI, try running `/usr/bin/chromedriver`. What do you get? – SiKing Jul 02 '15 at 18:43
  • This is what it output, `bash: /usr/bin/chromedriver: cannot execute binary file` – Manny Jul 02 '15 at 18:49

3 Answers3

5

Ubuntu has builds of chromium-chromedriver as .deb files for armhf.

On launchpad, therefore, you can find chromium-chromedriver armhf builds available for download. Just download the latest version, and since they have no dependencies, you can install by running dpkg -i chromium-chromedriver_58.0.3029.96-0ubuntu0.14.04.1174_armhf.deb. Then chromedriver will be available in /usr/lib/chromium-browser/chromedriver.

ioistired
  • 105
  • 3
  • 8
  • This didn't work for me. After downloading the [geckodriver v0.19.1 tarball](https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-arm7hf.tar.gz) and moving `geckodriver` to `/usr/local/bin/`, the command `geckodriver -b /usr/bin/firefox --webdriver-port 45753` yields the error `geckodriver: /lib/arm-linux-gnueabihf/libc.so.6: version 'GLIBC_2.18' not found (required by geckodriver)` – ConvexMartian Nov 19 '17 at 01:58
  • I gave instructions for chromedriver, not geckodriver. – ioistired Dec 04 '17 at 21:37
  • 3
    This worked for me and should be the accepted answer. The key is ensuring the chromedriver version matches the version of Chromium installed on the pi. In my case, I had to update Chromium. Once that was done, as long as I passed the `/usr/lib/chromium-browser/chromedriver` path when initializing the driver, everything worked great. – Alex Shaffer Jun 04 '18 at 18:44
3

At the moment Chrome Driver dont support ARM processors architecture anymore.

https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=95322

maco1717
  • 823
  • 10
  • 26
1

Update 2023: At this moment in time, chromium web driver for Raspberry Pi is available from repo via:

sudo apt install chromium-chromedriver

The driver will be at /usr/lib/chromium-browser/chromedriver

https://ivanderevianko.com/2020/01/selenium-chromedriver-for-raspberrypi

I successfully ran the following code under Bullseye 32-bit, slightly updated from original test program due to syntax change on find_element:

import time
from selenium import webdriver

driver = webdriver.Chrome()  # Optional argument, if not specified will search path.
driver.get('http://www.google.com/');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element("name", "q")
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()

Original chromium.org test that no longer works, deprecated: https://sites.google.com/a/chromium.org/chromedriver/getting-started

Info on updated syntax: Selenium - Python - AttributeError: 'WebDriver' object has no attribute 'find_element_by_name'

user48941
  • 11
  • 2