0

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.

asked Nov 19, 2015 at 11:13
4
  • I've copied your code into a file and ran it without any issues at all. I'm on Linux but I doubt that's what made the difference. Commented Nov 19, 2015 at 12:07
  • On my MAC, node version is 0.10.26 and npm version is 3.4.1. Don't know if the versions are out too old? Commented Nov 19, 2015 at 12:31
  • Node 0.10.26 may be too old. I run 4..2.2. Commented Nov 19, 2015 at 12:35
  • I updated node on my windows machine and it is running now. Thanks for your help Commented Nov 19, 2015 at 14:15

1 Answer 1

2

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.

answered Nov 19, 2015 at 14:17

1 Comment

I had the problem at ubuntu. So the update was hard but using this url was useful: digitalocean.com/community/tutorials/…

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

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.