Dan
Dan

Reputation: 2100

Running selenium with Javascript on Node.js

I am a noob to Javascript so apologies if my question is very trivial.

I am trying to run a selenium test that was wrote in Javascript. As I usually do, I just want to start with something simple and work from there. In my script I am just trying to load Google using chromedriver.

var webdriver = require("selenium-webdriver");

var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build();

driver.get("http://www.google.com");

On the CLI I navigate to the directory where the Test.js file is saved in and I run the command node Test.js. I always get this error in response;

C:\Selenium\node_modules\selenium-webdriver\_base.js:104
    vm.runInContext(opt_srcText, closure, src);
       ^
SyntaxError: Unexpected token )
at goog.loadModuleFromSource_ (C:\Selenium\node_modules\selenium-webdriver\l
at Object.goog.loadModule (C:\Selenium\node_modules\selenium-webdriver\lib\g
at C:\Selenium\node_modules\selenium-webdriver\lib\webdriver\promise.js:1:6
at Object.Context.closure.goog.retrieveAndExecModule_ (C:\Selenium\node_modu
at <anonymous>:1:6
at Context.closure.closure.vm.createContext.CLOSURE_IMPORT_SCRIPT (C:\Seleni
at Object.goog.importScript_ (C:\Selenium\node_modules\selenium-webdriver\li
at Object.goog.importModule_ (C:\Selenium\node_modules\selenium-webdriver\li
at Object.goog.writeScripts_ (C:\Selenium\node_modules\selenium-webdriver\li
at Object.goog.require (C:\Selenium\node_modules\selenium-webdriver\lib\goog

I originally ran this code on my Windows machine and when I was getting that error I put it down to Windows and Node.js no agreeing and tried it on my Mac. Still no luck as I was getting the exact same response.

On both machines I have node and npm installed. Previous to executing the tests I ran the command npm install selenium-webdriver and I also added chromedriver to my PATH.

I have no idea what I am doing wrong so if anyone can point me in the right direction, it'd be very much appreciated.

Upvotes: 0

Views: 1020

Answers (1)

Dan
Dan

Reputation: 2100

Turns out the version of node I was using was too old. Thanks to @Louis for your help in reaching this solution.

What I did was uninstall node and re-installed it with the latest version. I would imagine upgrading would work too.

Upvotes: 2

Related Questions