Running Selenium on NodeJs Running Selenium on NodeJs selenium selenium

Running Selenium on NodeJs


Your code looked fine to me, so I ran it to check that. I can confirm it runs fine (on macOS Sierra). Here's a link to the repo I created.

It looks like you might need to extend the wait for the page title though, sometimes I found loading Google's page title took longer than a second.

Another option would be to try a hosted service, rather than setting up your own selenium server. There are a variety available, I've just made Obehave for exactly this purpose. There is zero setup required - you can start writing your tests straight away.


Install the chromedriver via npm.

npm install chromedriver --save-dev

Then add chrome on top of the js:

var chrome = require('selenium-webdriver/chrome');

Finally script:

var webdriver = require('selenium-webdriver'),        By = webdriver.By, until = webdriver.until;        var webdriver = require('selenium-webdriver');var chrome = require('selenium-webdriver/chrome');var driver = new webdriver.Builder()    .forBrowser('chrome')    .build();driver.get('http://www.google.com/ncr').then(function(){    driver.findElement(By.name('q')).sendKeys('webdriver');    driver.findElement(By.name('btnK')).click();    driver.quit();});


chrome driver version and installed chrome must be compatible.