Posts: 3
Joined: Fri Sep 23, 2016 8:22 am

starting Chromium with crontab and selenium for autonomous website

Mon Jul 22, 2019 2:28 am

I'm listing here a python program with code that I have working on a Pi3b that has the purpose of starting Chromium automatically after restart of a Pi and logging into a website. I've obscured a few details to keep my application private. The Pi has a monitor connected on the HDMI i/f.

I struggled for a couple of days to get crontab and selenium to do what I needed and had to use a number of threads from others to piece this together.

The main challenge was getting crontab working. The main issues are:
ensuring #PATH is correct for chromium and setting DISPLAY.
Note that using a line such as -> @reboot DISPLAY=:0 && etc (DID NOT WORK) I had to have DISPLAY on a separate line.

make sure to install selenium

program name is, this is in a user directory Selenium, but that name is just a coincidence and not relevant to the installation of selenium

The actual purpose of my code is to login to a website, so the # lines are related to this purpose and I've kept them here in case it helps others doing similar.

Please note that I do not describe myself in any way as having linux expertise so can't enter into any detailed discussion on the operation or further fault finding.

Code: Select all

print('test1 start')

import time
import datetime
from selenium import webdriver
from import Options
from selenium.webdriver.common.keys import Keys

print ('imports')

now =
now_string = now.strftime("%Y-%m-%d %H:%M:%S") + " : "
print(now_string, 'web demo start')

# start chrome with options in kiosk mode
chromeoptions = Options()
driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver', 0, chromeoptions)

print ('sites')
#button = driver.find_element_by_name('commit').send_keys(Keys.RETURN)

print ('test1 end')
crontab -e

Code: Select all


@reboot python3 /home/pi/Selenium/ > /home/pi/Selenium/log.txt 2>&1

Return to “Troubleshooting”