2

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Rajat, thank you for your advice! I think this will solve the problem.
Rajat, I believe your suggestion solves part of the problem, but it seems the code still gives me the same error...
which operating system are you using ?
if you are using windows in cloud9 , make sure that you are using windows version of chromedriver. please correct this path = '/home/ec2-user/environment/testHW/chromedriver.exe' else it is correct for linux path = '/home/ec2-user/environment/testHW/chromedriver.exe'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.