This is my first attempt with selenium-webdriver on NodeJs in Windows 7 environment. Here is what I have done to try to make it work:
NodeJs 7.5 (officially supported by Selenium as noted on their Git https://github.com/SeleniumHQ/selenium/tree/master/javascript/node/selenium-webdriver)selenium-webdriver using npmchromedriver.exe 2.27 to "C:\Selenium Utilities\chromedriver" chromedriver to my PATH as C:\Selenium Utilities\chromedriver;Added my first test from Selenium Git page:
var webdriver = require('selenium-webdriver'),
By = webdriver.By, until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser('chrome')
.build();
driver.get('http://www.google.com/ncr');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.findElement(By.name('btnG')).click();
driver.wait(until.titleIs('webdriver - Google Search'), 1000);
driver.quit();
Tried running test via node test.js
As a result, I get error saying (excerpts):
"...throw new Error('Do not know how to build driver: ' + browser"
"Error: Do not know how to build driver: C; did you forget to call usingServer(url)?"
What am I doing wrong? Do I need to run a separate Selenium server in order to run this?
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();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With