6
votes

I am trying to run a simple code with selenium webdriver chrome on Cloud Function. I get the following error

Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

How do I specify chromedriver executable in Cloud Function?

Below is my code

from selenium import webdriver
import time
def test_webdriver(event=None, context=None):
    driver = webdriver.Chrome()
    driver.get('http://www.google.com/');
    time.sleep(5)
    search_box = driver.find_element_by_name('q')
1

1 Answers

2
votes

Headless Chrome is not currently available in the Cloud Functions runtime.

If you have the ability to switch to the Node.js runtime for your Cloud Function, you could use puppeteer which includes headless Chrome, but there is no equivalent for Python.

Another alternative would be to use Cloud Run instead of Cloud Functions. See here for an example: https://dev.to/di/using-headless-chrome-with-cloud-run-3fdp