3

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:

  1. Installed NodeJs 7.5 (officially supported by Selenium as noted on their Git https://github.com/SeleniumHQ/selenium/tree/master/javascript/node/selenium-webdriver)
  2. Installed selenium-webdriver using npm
  3. Downloaded chromedriver.exe 2.27 to "C:\Selenium Utilities\chromedriver"
  4. Added chromedriver to my PATH as C:\Selenium Utilities\chromedriver;
  5. 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();
    
  6. 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?

1
  • Did you solved it? Commented Nov 17, 2017 at 12:47

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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();
});

1 Comment

why `var chrome = require('selenium-webdriver/chrome)' if its never used?
1

chrome driver version and installed chrome must be compatible.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.