42

I am trying to login on facebook.com with selenium-webdriver.

var webdriver = require('selenium-webdriver'),
    By = require('selenium-webdriver').By,
    until = require('selenium-webdriver').until;

var driver = new webdriver.Builder()
    .forBrowser('firefox')
    .build();

driver.get('https://www.facebook.com/login');
driver.findElement(By.id('email')).sendKeys('****');
driver.findElement(By.id('pass')).sendKeys('*****');
driver.findElement(By.id('loginbutton')).click();

driver.findElement(By.linkText('Settings')).then(function(element) {
  console.log('Yes, found the element');
}, function(error) {
  console.log('The element was not found, as expected');
});
driver.quit();

It is giving error:

/home/shubham/node_modules/selenium-webdriver/index.js:25
const builder = require('./builder');
^^^^^
SyntaxError: Use of const in strict mode.
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/shubham/Music/amazon_login/test_22_4_16/sel_login.js:1:79)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

node --version v0.10.37

npm --version1.4.28

protractor --version Version 3.2.2

selenium-webdriver@2.53.1

Alex Rashkov
  • 9,833
  • 3
  • 32
  • 58
Shubham Batra
  • 2,357
  • 5
  • 29
  • 48

6 Answers6

153

Updating nodejs solved the issue:

npm cache clean -f
sudo npm install -g n
sudo n stable
node --version
node app.js

You have to run the second and third command as root/administrator.

tenbits
  • 7,568
  • 5
  • 34
  • 53
  • 1
    I noticed you use `nodejs` as command line. It should be `node`. Can you print the "node --version"? – tenbits Apr 22 '16 at 10:04
  • node --version && nodejs --version && whereis node && /usr/local/bin/node --version && sudo mv node node_0_12_2 && whereis nodejs && sudo ln -s /usr/bin/nodejs node – Torin Finnemann Apr 07 '17 at 13:01
  • Above solution only updates the node version which would have updated the node version from `v0.10.37` to a newer version which is 4 or later which supports `const` in strict mode so the error would have resolved. A proper solution can be found under https://stackoverflow.com/questions/43932038/husky-giving-error-syntaxerror-use-of-const-in-strict-mode/44168690#44168690 – G G May 24 '17 at 21:40
  • Updating NodeJS solves this problem. But, After running `sudo npm install -g n` you might get following error: `npm: relocation error: npm: symbol SSL_set_cert_cb, version libssl.so.10 not defined in file libssl.so.10 with link time reference` In order to overcome this error, try upgrading openssl using the below command: `sudo yum update openssl` – Dibya Sahoo Nov 07 '17 at 07:04
12

n stable wouldn't do the trick for me. On the other hand,

nvm install stable

That actually got me to last nodejs version. Apparently n stable won't get pass v0.12.14 for me. I really don't know why.

Note: nvm is Node Version Manager, you can install it from its github page. Thanks @isaiah for noting that nvm is not a known command.

Alf Sanzo
  • 141
  • 2
  • 9
4

For me it was more simple to solve, just going to the Node web site, get and install the LTS version.

Pedro Benevides
  • 1,970
  • 18
  • 19
2

Update your node and it will resolve this problem.

Root
  • 147
  • 2
  • 4
0

Updating NodeJS solves this problem. But, after running sudo npm install -g n you might get following error:

npm: relocation error: npm: symbol SSL_set_cert_cb, version libssl.so.10 not defined in file libssl.so.10 with link time reference

In order to overcome this error, try upgrading openssl using the below command:

sudo yum update openssl
Dibya Sahoo
  • 839
  • 3
  • 9
  • 30
-3

That error means your node's publish is low than the need. carefully to update the node of your computer.