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
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.