When I run my nodejs 12.x code calling selenium, I am getting the error below.
At the top level of my directory structure, I have my index.js file, a lib folder and a node_modules folder.
I am preparing the code on a Mac and then zipping it, uploading to S3 and running it in Lambda.
Where should my chrome and chromedriver executables be? I don't think I can use npm to install them as I think I need the linux versions for running in Lambda?
This is the error I am getting:
{ "errorType": "Error", "errorMessage": "The ChromeDriver could not be found on the current PATH. Please download the latest version of the ChromeDriver from http://chromedriver.storage.googleapis.com/index.html and ensure it can be found on your PATH.", "trace": [ "Error: The ChromeDriver could not be found on the current PATH. Please download the latest version of the ChromeDriver from http://chromedriver.storage.googleapis.com/index.html and ensure it can be found on your PATH.", " at new ServiceBuilder (/var/task/node_modules/selenium-webdriver/chrome.js:232:13)", " at getDefaultService (/var/task/node_modules/selenium-webdriver/chrome.js:321:22)", " at Function.createSession (/var/task/node_modules/selenium-webdriver/chrome.js:695:44)", " at createDriver (/var/task/node_modules/selenium-webdriver/index.js:155:33)", " at Builder.build (/var/task/node_modules/selenium-webdriver/index.js:662:16)", " at Runtime.exports.handler (/var/task/index.js:38:26)", " at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)" ] }
This is my code
'use strict';
exports.handler = async (event, context, callback) => {
var webdriver = require('selenium-webdriver');
var chrome = require('selenium-webdriver/chrome');
var builder = new webdriver.Builder().forBrowser('chrome');
var chromeOptions = new chrome.Options();
const defaultChromeFlags = [
'--headless',
'--disable-gpu',
'--window-size=1280x1696', // Letter size
'--no-sandbox',
'--user-data-dir=/tmp/user-data',
'--hide-scrollbars',
'--enable-logging',
'--log-level=0',
'--v=99',
'--single-process',
'--data-path=/tmp/data-path',
'--ignore-certificate-errors',
'--homedir=/tmp',
'--disk-cache-dir=/tmp/cache-dir'
];
chromeOptions.setChromeBinaryPath("/var/task/lib/chrome");
chromeOptions.addArguments(defaultChromeFlags);
builder.setChromeOptions(chromeOptions);
//*****this is the problem line****//
var driver = builder.build();
driver.get(event.url);
driver.getTitle().then(function(title) {
console.log("Page title for " + event.url + " is " + title)
callback(null, 'Page title for ' + event.url + ' is ' + title);
});
driver.quit();
};