Having issues in running python selenium script with chrome driver and headless chromium

0

I have the following lambda code

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

def lambda_handler(event, context):
    options = Options()
    options.binary_location = '/opt/bin/headless-chromium'
    options.add_argument('--headless')
    options.add_argument('--no-sandbox')
    options.add_argument('--single-process')
    options.add_argument('--disable-dev-shm-usage')

    driver = webdriver.Chrome('/opt/bin/chromedriver',chrome_options=options)
    
    driver.get('https://www.google.com/')
    title = driver.title

    driver.close()
    driver.quit()

    response = {
        "statusCode": 200,
        "body": title
    }

    return response

I have added 2 layers called dependencies_layer and chromedriver_layer with dependencies_layer containing selenium library and chromedriver_layer containing bin and lib folders . bin contains chromedriver and headless-chromium executable and lib contains their shared libraries requried for execution . but whenever I run the function it returns this Error :

"errorMessage": "Message: Service /opt/bin/chromedriver unexpectedly exited. Status code was: 1\n", "errorType": "WebDriverException", "stackTrace": [ " File "/var/task/lambda_function.py", line 12, in lambda_handler\n driver = webdriver.Chrome('/opt/bin/chromedriver',chrome_options=options)\n", " File "/opt/python/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in init\n self.service.start()\n", " File "/opt/python/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 96, in start\n self.assert_process_still_running()\n", " File "/opt/python/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 107, in assert_process_still_running\n raise WebDriverException(\n" ] }

anyone knows what maybe the issue ?

No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions