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?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
HQMA
  • 125
  • 1
  • 8

1 Answers1

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.

Rajat
  • 118
  • 1
  • 5
  • 1
    Rajat, thank you for your advice! I think this will solve the problem. – HQMA Jun 29 '19 at 12:08
  • Rajat, I believe your suggestion solves part of the problem, but it seems the code still gives me the same error... – HQMA Jul 01 '19 at 04:29
  • which operating system are you using ? – Rajat Jul 01 '19 at 05:43
  • 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' – Rajat Jul 02 '19 at 04:14