Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium Webdriver Chrome Fails on Cloud Function

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')
like image 396
Saf Avatar asked Oct 21 '19 14:10

Saf


1 Answers

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

like image 84
Dustin Ingram Avatar answered Sep 19 '22 21:09

Dustin Ingram