1
votes

I'm trying to run a script via scheduler which uses selenium but it shows the following error - Message: Service /app/.apt/opt/google/chrome/chrome unexpectedly exited. Status code was: -6 I've used both the buildpacks - https://github.com/heroku/heroku-buildpack-chromedriver.git https://github.com/heroku/heroku-buildpack-xvfb-google-chrome

The script is:

chrome_exec_shim = "/app/.apt/opt/google/chrome/chrome"
opts = webdriver.ChromeOptions()
opts.binary_location = chrome_exec_shim
driver = webdriver.Chrome(executable_path=chrome_exec_shim, chrome_options=opts)
3
You are not getting the right path you need to give the path to chromeDrive - Moshe Slavin
How can I fetch the right path and where to add it? - Arjunsingh

3 Answers

1
votes

What you should do is download the Chrome driver here. You can either put it in the chrome package that way you don't need to set the path at all. ( In my experience better to put in the path) or you can just give the path to the downloaded driver it can be in the project folder (recommend).

Just change the variable chrome_exec_shim to the path of the driver.

1
votes
chrome_exec_shim = "/app/.apt/opt/google/chrome/chrome"
opts = webdriver.ChromeOptions()
opts.binary_location = chrome_exec_shim
opts.addArguments("--no-sandbox");
opts.addArguments("--disable-gpu");
driver = webdriver.Chrome(executable_path=chrome_exec_shim, chrome_options=opts)

Try with this code. You must add the arguments of the chromeoption and it will work. I tried this and its working for me.

1
votes

After downloading the chromedriver, it was giving an error that binary was not found. Gave the address of chrome in the executable path and the path of chrome driver in the chrome options. That too resulted in the error, and after adding --disable-gpu and --no-sandbox arguments in the chrome options, it got resolved. Thanks for the help... :) The code that ran, at last, is below -

from selenium import webdriver
import os

chrome_exec_shim = os.environ.get("GOOGLE_CHROME_BIN", "chromedriver")
opts = webdriver.ChromeOptions()
opts.binary_location = chrome_exec_shim
opts.add_argument('--disable-gpu')
driver = webdriver.Chrome(executable_path='/app/development/chromedriver', chrome_options=opts)