title: Selenium with chromedriver doesn't start via cron
body: <p>Python script with Selenium and Chromedriver in <strong>headless mode</strong> on CentOS7 runs fine when called manually.</p>
  
  <pre><code>options = webdriver.ChromeOptions()
  options.add_argument('headless')
  options.add_argument('no-sandbox')
  self.driver = webdriver.Chrome(chrome_options=options)
  </code></pre>
  
  <p>When starting script with crontab however it throws this exception at line 4 (above). Full traceback at bottom.</p>
  
  <pre><code>selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.38.552522
  </code></pre>
  
  <p>Cron is setup with crontab -e</p>
  
  <pre><code>* * * * * cd /to/path &amp;&amp; /to/path/.virtualenvs/selenium/bin/python /to/path/script.py -t arg1 arg2 &gt; /to/path/log.txt 2&gt;&amp;1
  </code></pre>
  
  <p>This produced errors like chromedriver couldn't be found. I then added following to crontab -e. <br>
  1) Use bash instead of sh, although starting python script manually from sh works fine<br>
  2) Specify path to chromedriver</p>
  
  <pre><code>SHELL=/bin/bash
  PATH=/usr/local/bin/
  </code></pre>
  
  <p>I tried different suggestions found on the web like adding --no-sandbox options to chromedriver in my script. All didn't help. Please note that I am using chrome in headless mode, so I think I don't need this export DISPLAY=:0 stuff in cron, or Xvfb libs as it used to be.</p>
  
  <p>Python 3.6.1<br>
  Selenium 3.4.3<br>
  Chromedriver 2.38.552522<br>
  google-chrome-stable 65.0.3325.181<br></p>
  
  <p>Full traceback</p>
  
  <pre><code>Exception in thread &lt;name&gt;:
  Traceback (most recent call last):
    File "/usr/lib64/python3.6/threading.py", line 916, in _bootstrap_inner
      self.run()
    File "/usr/lib64/python3.6/threading.py", line 864, in run
      self._target(*self._args, **self._kwargs)
    File "/path/to/script.py", line 53, in start
      self.site_scrape(test_run)
    File "/path/to/script.py", line 65, in site
      self.driver = webdriver.Chrome(chrome_options=options)
    File "/home/&lt;user&gt;/.virtualenvs/selenium/lib64/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
      desired_capabilities=desired_capabilities)
    File "/home/&lt;user&gt;/.virtualenvs/selenium/lib64/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 98, in __init__
      self.start_session(desired_capabilities, browser_profile)
    File "/home/&lt;user&gt;/.virtualenvs/selenium/lib64/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 188, in start_session
      response = self.execute(Command.NEW_SESSION, parameters)
    File "/home/&lt;user&gt;/.virtualenvs/selenium/lib64/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 256, in execute
      self.error_handler.check_response(response)
    File "/home/&lt;user&gt;/.virtualenvs/selenium/lib64/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
      raise exception_class(message, screen, stacktrace)
  selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
    (Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Linux 4.14.12-x86_64-linode92 x86_64)
  </code></pre>