Execute Python (selenium) script in crontab

As seen here, you need to give cron a display:

30 5 * * * export DISPLAY=:0; /home/me/good_morning.sh

A quick guess, your job fails to run because it requires an X session. You should setup your test script to run in a headless mode.

update:
Your trace says exactly what I meant, firefox does not run without X, or a display if you want.

 The output was: Error: no display specified\n' 

Save yourself more trouble, read the link I posted.


You can do it without crontab.

I found schedule modul: GIThub/schedule

Now your code should look like:

import schedule
import time
def job():
    import pickle
    from selenium import webdriver
    driver = webdriver.Firefox()
    driver.get('http://www.google.com')
    t=driver.current_url
    pickle.dump(t,open('noreal','wb'))
schedule.every(1).minutes.do(job)
while True:
    schedule.run_pending()
    time.sleep(1)

It is not best solution but it works.