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 ?

답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠