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.
-
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.Louis– Louis2015年11月19日 12:07:18 +00:00Commented 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?Dan– Dan2015年11月19日 12:31:25 +00:00Commented Nov 19, 2015 at 12:31
-
Node 0.10.26 may be too old. I run 4..2.2.Louis– Louis2015年11月19日 12:35:40 +00:00Commented Nov 19, 2015 at 12:35
-
I updated node on my windows machine and it is running now. Thanks for your helpDan– Dan2015年11月19日 14:15:58 +00:00Commented Nov 19, 2015 at 14:15
1 Answer 1
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.