Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97804

How to setup Selenium with headless Chrome/Firefox on Raspbian Buster

$
0
0

I have gotten this to work in Jessie/Stretch with previous Chrome/Firefox versions but can't seem to get it to work with Raspberry Pi 3B or 4 running Raspbian Buster and the latest Selenium, 3.141.0 in Python.

For Chrome, I install chromium-chromedriver via apt and then run the code below:

from selenium import webdriver
from pyvirtualdisplay import Display

options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome('/usr/bin/chromedriver', chrome_options=options)
driver.get('https://www.google.com')
driver.close()
display.stop()

It returns the below error:

Message: chrome not reachable
  (Session info: headless chrome=74.0.3729.157)
  (Driver info: chromedriver=74.0.3729.157 (7b16107ab85c5364cdcd0b2dea2539a1f2dc327a-refs/branch-heads/3729@{#998}),platform=Linux 4.19.75-v7+ armv7l)

Traceback (most recent call last):
  File "SeleniumDebugExample.py", line 42, in <module>
    print(driver.page_source)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 670, in page_source
    return self.execute(Command.GET_PAGE_SOURCE)['value']
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
WebDriverException: Message: chrome not reachable
  (Session info: headless chrome=74.0.3729.157)
  (Driver info: chromedriver=74.0.3729.157 (7b16107ab85c5364cdcd0b2dea2539a1f2dc327a-refs/branch-heads/3729@{#998}),platform=Linux 4.19.75-v7+ armv7l)

For Firefox, since iceweasel is no longer available I install firefox-esr via apt and get the latest ARM geckodriver, which is currently 0.23.0, from https://github.com/mozilla/geckodriver/releases then run the code below:

from selenium import webdriver
from pyvirtualdisplay import Display
from selenium.webdriver.firefox.options import Options

options = Options()
options.headless = True
capabilities = webdriver.DesiredCapabilities().FIREFOX
capabilities["marionette"] = False
driver = webdriver.Firefox(options=options, executable_path='/srv/main/geckodriver', capabilities=capabilities)
driver.get('https://www.google.com')
print(driver.page_source)
driver.close()
display.stop()

This returns the error:

Message: Can't load the profile. Possible firefox version mismatch. You must use GeckoDriver instead for Firefox 48+. Profile Dir: /tmp/tmpxMUUcF If you specified a log_file in the FirefoxBinary constructor, check it for details.

Traceback (most recent call last):
  File "SeleniumDebugExample.py", line 50, in <module>
    driver = webdriver.Firefox(options=options, executable_path='/srv/main/geckodriver', capabilities=capabilities)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 191, in __init__
    self.binary, timeout)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 73, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 114, in _wait_until_connectable
    % (self.profile.path))
WebDriverException: Message: Can't load the profile. Possible firefox version mismatch. You must use GeckoDriver instead for Firefox 48+. Profile Dir: /tmp/tmpxMUUcF If you specified a log_file in the FirefoxBinary constructor, check it for details.

I am specifying geckodriver though so I am not sure what the issue is...

If anyone has gotten headless selenium to work on Raspbian Buster and can share some could it would be greatly appreciated!


Viewing all articles
Browse latest Browse all 97804

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>