Skip to main content
  1. About
  2. For Teams
Asked
Viewed 7k times
5

I am having some trouble setting up Selenium WebDriverJS. My goal is to run selenium tests on Chrome browser using Javascript (node).

I am following the instructions on https://code.google.com/p/selenium/wiki/WebDriverJs as well as https://code.google.com/p/chromedriver/wiki/GettingStarted

First I downloaded the chromedriver, and ran it on a terminal:

$ ./chromedriver
Starting ChromeDriver (v2.2) on port 9515

And then, I installed selenium-webdriver:

$ npm install selenium-webdriver
npm http GET https://registry.npmjs.org/selenium-webdriver
npm http 304 https://registry.npmjs.org/selenium-webdriver
[email protected] node_modules/selenium-webdriver

Then, I started node console and tried to build the webdriver instance

$ node
> var webdriver = require('selenium-webdriver')
undefined
> var driver = new webdriver.Builder().usingServer('http://localhost:9515/wd/hub').withCapabilities(webdriver.Capabilities.chrome()).build();
undefined
> 
timers.js:103
            if (!process.listeners('uncaughtException').length) throw e;
                                                                      ^
UnknownCommandError: unknown command: wd/hub/session
    at new bot.Error (/selenium/node_modules/selenium-webdriver/lib/atoms/error.js:109:18)
    at Object.bot.response.checkResponse (/selenium/node_modules/selenium-webdriver/lib/atoms/response.js:103:11)
    at /selenium/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:133:20
    at /selenium/node_modules/selenium-webdriver/lib/goog/base.js:1178:15
    at webdriver.promise.ControlFlow.runInNewFrame_ (/selenium-webdriver/lib/webdriver/promise.js:1438:20)
    at notify (/selenium/node_modules/selenium-webdriver/lib/webdriver/promise.js:328:12)
    at notifyAll (/selenium/node_modules/selenium-webdriver/lib/webdriver/promise.js:297:7)
    at fulfill (/selenium/

And now I am blocked. Can someone help me on this, please? What am I missing here?

Thanks

1 Answer 1

15

Couple of things here.

  1. By default, the chromedriver server handles commands at /, not /wd/hub. So you should be able to do:

    new webdriver.Builder().usingServer('http://localhost:9515').build();
    
  2. If you want the chromedriver to have the same signature as the standalone Selenium server, start it with --url-base=/wd/hub.

  3. There's no need to start the chromedriver yourself - selenium-webdriver will do it for you if you request Chrome and omit a server location (make sure chromedriver can be found on your system PATH):

    new webdriver.Builder()
        .withCapabilities(webdriver.Capabilities.chrome())
        .build();
    
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot, it worked perfectly. Now, if I may ask, is there a way to specify the location of the chromedriver in the code instead of using system PATH?
I had to dig the source code, but it was worth it! new chrome.ServiceBuilder(PATH_TO_BINARY).build() was the key :)

Your Answer

Post as a guest

Required, but never shown

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.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.