Chromedriver and Selenium WebDriver


#1

Hi!

I was trying to use Selenium WebDriver and Chromedriver for a project. I had the following code:

require('chromedriver');
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder()
  .forBrowser('chrome')
  .build();

However, I get an error about the Chrome binary? I believe the issue has something to do with this binary not being found on the PATH, but I’m unsure how to go about resolving this. Any help would be appreciated :slight_smile: Error below:

WebDriverError: unknown error: cannot find Chrome binary
  (Driver info: chromedriver=2.46.628388 (4a34a70827ac54148e092aafb70504c4ea7ae926),platform=Linux 4.4.0-1066-aws x86_64)

    at Object.checkLegacyResponse (/rbd/pnpm-volume/5c14e12f-0790-4195-ba5f-0315077802ad/node_modules/.registry.npmjs.org/selenium-webdriver/3.6.0/node_modules/selenium-webdriver/lib/error.js:546:15)

    at parseHttpResponse (/rbd/pnpm-volume/5c14e12f-0790-4195-ba5f-0315077802ad/node_modules/.registry.npmjs.org/selenium-webdriver/3.6.0/node_modules/selenium-webdriver/lib/http.js:509:13)

    at doSend.then.response (/rbd/pnpm-volume/5c14e12f-0790-4195-ba5f-0315077802ad/node_modules/.registry.npmjs.org/selenium-webdriver/3.6.0/node_modules/selenium-webdriver/lib/http.js:441:30)

    at <anonymous>

    at process._tickCallback (internal/process/next_tick.js:189:7)

From: Task: WebDriver.createSession()

    at Function.createSession (/rbd/pnpm-volume/5c14e12f-0790-4195-ba5f-0315077802ad/node_modules/.registry.npmjs.org/selenium-webdriver/3.6.0/node_modules/selenium-webdriver/lib/webdriver.js:769:24)

    at Function.createSession (/rbd/pnpm-volume/5c14e12f-0790-4195-ba5f-0315077802ad/node_modules/.registry.npmjs.org/selenium-webdriver/3.6.0/node_modules/selenium-webdriver/chrome.js:761:15)

    at createDriver (/rbd/pnpm-volume/5c14e12f-0790-4195-ba5f-0315077802ad/node_modules/.registry.npmjs.org/selenium-webdriver/3.6.0/node_modules/selenium-webdriver/index.js:170:33)

    at Builder.build (/rbd/pnpm-volume/5c14e12f-0790-4195-ba5f-0315077802ad/node_modules/.registry.npmjs.org/selenium-webdriver/3.6.0/node_modules/selenium-webdriver/index.js:642:16)

#2

Hi @ericyangwa, welcome to the Glitch Forums!

There isn’t a straightforward way to do this. The container your project runs in is a headless Ubuntu that doesn’t have Chrome installed. You might be able to work around this by downloading the appropriate Chrome .deb file and installing it using dpkg and the --force-no-root option.

If that’s successful then you’ll need to tell Selenium where to find Chrome, since it won’t be on the path by default. Apparently. there’s a mechanism for this.

You might also look at https://www.npmjs.com/package/selenium-standalone, but I have no idea how well that would work.

Let us know if you’re able to get this running - I think there are probably a few other community members that would like to know how to make it work as well.


#3

Thanks @cori ! I’ll give these a try. Will have to see if I can install chrome via command line!


#5

You’ll likely need to use a true headless browser (like PhantomJS) because the projects don’t have a display to run on. Unfortunately for this case, we don’t even have xvfb installed on the container to simulate a display.


#6

Yea. The project uses PhantomJS to take screenshots of a certain site, but it unfortunately has some elements that don’t load completely when I use the render function to take a ss, so I wanted to use Selenium WebDriver to analyze some css elements to determine when something has loaded before actually taking the screenshot. Not sure if this is the best way to approach it though haha.


#7

Per the Mozilla docs it seems like perhaps you could use Firefox in a headless fashion even without installing xvfb if you’re not completely attached to Chrome, but I think you’re going to run into disk space problems there, for the time being; the Firefox install is far too large to fit in the container’s available disk space (and so is the Chrome binary, in all retrospective likelihood).


#8

I managed to fix it, but it doesn’t really answer my original question haha. Because what I really wanted was a Phantom browser to start with, with just:

const webdriver = require('selenium-webdriver');
var capabilities = {
   'browserName' : 'phantomjs'
}

var driver = new webdriver.Builder().
  withCapabilities(capabilities).
  build();

driver... (do whatever)

worked! Thanks for all the help everyone :slight_smile:


How to check logs of which packages updated?