Sid
Sid

Reputation: 4055

Selenium chromedriver fails from cron job?

I am trying to use cron to start a session of chromedriver

I keep getting this error:

(unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/lib/chromium-browser/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.) (Driver info: chromedriver=71.0.3578.98,platform=Linux 4.15.0-45-generic x86_64)

It works fine if I run from Pycharms

options = Options()
options.add_argument('--no-sandbox')
driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver", options=options)

I have tried a bunch of things, for example:

options.add_argument("--headless")

But it just doesn't work from cron.

Upvotes: 3

Views: 1272

Answers (1)

halfer
halfer

Reputation: 20437

(Posted solution on behalf of the question author, to move it to the answer space).

Found the problem.

Basically cron doesn't know where to display. So we need to tell it in crontab where to display i.e.

export DISPLAY=:0;

You need to find the :0 part using grep.

Don't forget the ;.

Upvotes: 5

Related Questions