For a scheduled task I want the selenium webdriver to be executed with python script.

I have tried the following solution:

  1. https://stackoverflow.com/questions/50117377/selenium-with-chromedriver-doesnt-start-via-cron

But it has not resolved the problem.

Location of chromdriver:


1 Answer 1


Specify full paths in cron.

The next cron job includes:

  • DISPLAY variable specified to access your display in case if you do not want to use headless mode. Use $ env | grep DISPLAY to get it.
  • PATH variable with path to chromedriver specifying. I've copied chromedriver to /usr/local/bin
  • Full path to python3.8
  • Full path to python script

$ crontab -e:

* * * * * export DISPLAY=:0; PATH=$PATH:/usr/local/bin; /usr/bin/python3.8 /home/user/PycharmProjects/seleniumtest/seltest.py build

In your case specify path to your chromdriver location:

* * * * * export DISPLAY=:0; PATH=$PATH:/home/user/Documents/python/Chromedriver; /usr/bin/python3.8 /home/user/PycharmProjects/seleniumtest/seltest.py build

Note: I've created a python project in PyCharm using the next parameters:

enter image description here enter image description here enter image description here

The script is taken from here:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
assert "No results found." not in driver.page_source

Additionally I have been required to install some packages:

$ sudo apt install python3-pip
$ pip3 install selenium
$ cd ~/Downloads
$ unzip chromedriver_linux64.zip
$ sudo cp chromedriver /usr/local/bin/
  • Thanks for you help May 9, 2020 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.