HQMA
HQMA

Reputation: 125

Unable to run chromedriver using Python & selenium in cloud9 & aws

I have tried to perform scraping using python and selenium in cloud9 and aws lambda, however, it seems there is some problem in (path of) chromedriver and it does not run. my code is;

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

def lambda_handler(event, context):
    options = Options()
    options.add_argument('--headless')
    path = '/home/ec2-user/environment/testHW/chromedriver.exe'
    url = 'https://www.google.com'
    driver = webdriver.Chrome(executable_path=path, chrome_options=options)
    driver.get(url)
    driver.save_screenshot('screenshot.png')

and I have put chromedriver in the corresponding location. However, I have got an error message as below;

Response
    {
        "errorMessage": "Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home\n",
        "errorType": "WebDriverException",
        "stackTrace": [
            [
                "/var/task/testHW/lambda_function.py",
                11,
                "lambda_handler",
                "driver = webdriver.Chrome(executable_path=path, chrome_options=options)"
            ],
            [
                "/var/task/selenium/webdriver/chrome/webdriver.py",
                73,
                "__init__",
                "self.service.start()"
            ],
            [
                "/var/task/selenium/webdriver/common/service.py",
                83,
                "start",
                "os.path.basename(self.path), self.start_error_message)"
            ]
        ]
    }

    Function Logs
    Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
    : WebDriverException
    Traceback (most recent call last):
      File "/var/task/testHW/lambda_function.py", line 11, in lambda_handler
        driver = webdriver.Chrome(executable_path=path, chrome_options=options)
      File "/var/task/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
        self.service.start()
      File "/var/task/selenium/webdriver/common/service.py", line 83, in start
        os.path.basename(self.path), self.start_error_message)
    selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

    Request ID
    82bcf27f-255e-431d-ae13-6a0efba8d69a

Could anyone suggest what is the problem?

Upvotes: 2

Views: 1664

Answers (1)

Rajat
Rajat

Reputation: 118

Message: 'chromedriver.exe' executable needs to be in PATH. This error means it need an executable path

from your directory structure it seems you are using linux base os. go for this link and download chromedriver for linux.

Open directory where chromedriver is placed , Now open terminal and enter following command to permit executable permission to the chromedriver.

sudo chmod +x chromedriver

I hope it will work.

Upvotes: 1

Related Questions