Reputation: 1733
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 npm
chromedriver.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?
Upvotes: 3
Views: 5903
Reputation: 91
Remove "SELENIUM_BROWSER" variable from environment variables or add quotes its path.
"Error: Do not know how to build driver: C; did you forget to call usingServer(url)?"
C letter in the error is the first letter of C:\ in the path of the SELENIUM_BROWSER variable.
Upvotes: 0
Reputation: 117
chrome driver version and installed chrome must be compatible.
Upvotes: 1
Reputation: 329
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();
});
Upvotes: 1
Reputation: 131
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.
Upvotes: 2