3

Okay, I think I've done my homework here... I can't for the life of me get the official Selenium Webdriver npm module to work; I'm stuck. Here's my versions of everything...

Ubuntu 14.04

NodeJS v0.12.0, underneath Express 4.0

Java OpenJDK 1.6.0_34

Chrome Stable 33.0.1750.152

Chromedriver 2.9


I created a Digital Ocean droplet and chose Ubuntu 14.04 with Node already installed. I apt-get installed Chrome, Git and Java, and then npm install'd PM2 and Grunt.

I downloaded Chromedriver 2.9, gave it permission to be executed (chmod a+x), and moved it to /usr/local/bin. I can run "chromedriver" anywhere and it will give the message Starting ChromeDriver (v2.9.248304) on port 9515. Also, netstat -lp confirms that Chromedriver is listening on port 9515; it's working.

I used the Selenium Standalone npm module to get the Selenium jar for the selenium-webdriver module to use. I ran these commands...

npm install selenium-standalone@latest -g

selenium-standalone install

and it told me that the Selenium .jar had been downloaded to... /usr/local/lib/node_modules/selenium-standalone/.selenium/selenium-server/2.44.0-server.jar

Onto the most important stuff... the Selenium Webdriver module. I ran these commands, according to the npm documentation, in the root of my Node app.

export SELENIUM_SERVER_JAR=/usr/local/lib/node_modules/selenium-standalone/.selenium/selenium-server/2.44.0-server.jar

SELENIUM_BROWSER=chrome

My Code

It's basically straight from the WebdriverJS documentation.

function init(value, cb) {

  console.log('Started task...');

  var webdriver = require('selenium-webdriver'),
  driver = new webdriver.Builder().
  withCapabilities(webdriver.Capabilities.chrome()).
  build();

  driver.get('http://www.google.com');
  driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
  driver.findElement(webdriver.By.name('btnG')).click();
  driver.wait(function() {
    return driver.getTitle().then(function(title) {
      return title === 'webdriver - Google Search';
    });
  }, 1000);

  driver.quit();

  console.log('done');
  
  cb();
}

init(true, function() {
  
  // do other stuff
});

Output

Terminal

Other things I've tried

I read here that you were supposed to install xvfb with it and then run this command...

Xvfb :0 -ac -screen 0 1024x768x24 &

but it didn't make a difference.

I tried using Oracle's Java from their repo, and OpenJDK 1.7. I've also seen a lot of command line options you can pass in by executing java -jar -flagsandstuff, but it doesn't seem like that's the solution to using the Selenium Webdriver module. I'm out of ideas and frustrated.

Community
  • 1
  • 1
Taylor Evanson
  • 367
  • 2
  • 16
  • did you try `ctrl + r`? – jordan Feb 10 '15 at 20:32
  • Chromedriver 2.9 is old. How about using a newer version? Also, if I cut and paste your code into a file here and execute it, it works. I have Chormedriver 2.11. (I should upgrade...) You do **not** need `selenium-standalone` or to mess with environment variables or to use `xvfb` or to use Java. – Louis Feb 10 '15 at 23:29
  • I don't want to run it on your computer, I want to run it on mine. ;) Same issue on 2.14, just triple checked. The purpose of xvfb is to make it usable on a server with no gui, and the environment variables are for Node; I do need them if i'm going to use the selenium-webdriver module. It needs to be automated, otherwise I would just call it from the command line with `java -jar`. Any other ideas? – Taylor Evanson Feb 10 '15 at 23:48
  • It looks like you moved on and are using headless browser, probably right thing to do. Just wanted to check, are you running tests from Jenkins? Perhaps you need to setup `DISPLAY` from where you run the tests as well according to this post, if you haven't checked already http://stackoverflow.com/questions/22558077/unknown-error-chrome-failed-to-start-exited-abnormally-driver-info-chromedri – nilesh Feb 12 '15 at 18:33
  • nilesh, I actually wasn't running it from Jenkins! But I did try some environment variable stuff with `DISPLAY:99` and still didn't have any luck. Thank you though, for reals! Most relevant answer ^^ – Taylor Evanson Feb 12 '15 at 19:06

1 Answers1

0

It's not worth it; there are better headless browser modules that run on top of PhantomJS. I finally found this post that has about 30 different solutions! I went with Nightmare.

Headless Browser and scraping - solutions [closed]

Community
  • 1
  • 1
Taylor Evanson
  • 367
  • 2
  • 16