Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Quality Assurance Introduction to Selenium Test Drive Selenium Installation

Logan R
Logan R
22,989 Points

Can't import Selenium in Node terminal

Hi,

I can't get selenium to import inside the node terminal while working in Workspaces.

$ npm install selenium-webdriver
$ npm install chromdriver
> const selenium = require("selenium-webdriver");                                                              
/home/treehouse/workspace/node_modules/selenium-webdriver/lib/http.js:454                                      
  async execute(command) {                                                                                     
        ^^^^^^^                                                                                                
SyntaxError: Unexpected identifier                                                                             

I tried googling the error, but nothing really came up. Any help would be appreciated!

5 Answers

Seth Kroger
Seth Kroger
56,407 Points

What version of node/npm are you using? That error could be because you're using an older version of node that doesn't recognize the async keyword.

Logan R
Logan R
22,989 Points

I thought about this being the issue but I'm not allowed to update node or npm through yum. I don't have sudoers access on workspaces. I could try installing locally from source.

Node is v6.11.1, npm is 3.10.10. He says at the start of the course that version 6 should be okay but maybe not lol.

Seth Kroger
Seth Kroger
56,407 Points

I see Selenium bumped up to 4.0.0.alpha.1 on npm. Woot, breaking changes!

Node needs to be version 8/9 to use async/await. If Node isn't upgradable, I'd suggest specifying the prior version for selenium-driver (3.6.0 for node) by the looks of it in package.json on re-install.

Tagging in Craig Dennis

Craig Dennis
Craig Dennis
Treehouse Teacher

Yes thanks, please use the older version of selenium. Will work on getting the instructions in there. Thanks for the ping Seth Kroger !

Ok, I have a newer version of Node than what you are using in the tutorial; but, I'm having the same issue.

Craig Dennis
Craig Dennis
Treehouse Teacher

Hey David!

Check the teachers notes on this video. It has the correct command.

Thanks!

VIDEO 4:49

    > const selenium = require("selenium-webdriver@3");
       Error: Cannot find module 'selenium-webdriver@3'
        at (...etc.)

     > const selenium = require("selenium-webdriver");
        TypeError: Identifier 'selenium' has already been declared
         at (...etc.)

I'm not getting: undefined

Craig Dennis
Craig Dennis
Treehouse Teacher

Only change the npm install ...rest of the code is the same. The error there is from using const after already using one.

Again just the npm install changes, not the code.

Sorry for the confusion!

Well now I'm getting a TypeError: Identifier 'driver' has already been declared for: const driver = new selenium.Builder().forBrowser("chrome").build(); But yet, when I go ahead with the tutorial, I see: ReferenceError: driver is not defined

Craig Dennis
Craig Dennis
Treehouse Teacher

Hi David,

const makes it so you can no longer define a variable with that name. So you declared driver with const, and then tried to declare it again. Doesn't have anything to do with versioning at this point.

Give it another go! Hope that helps!

Emin Hatam
Emin Hatam
613 Points

Can someone please help with this? I keep getting this message and cant continue. I do not know what does this message mean. Thank you in advance.

Emins-MacBook-Pro:~ primeacctemin$ node

const selenium = require("selenium-webdriver"); { Error: Cannot find module 'selenium-webdriver' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15) at Function.Module._load (internal/modules/cjs/loader.js:529:25) at Module.require (internal/modules/cjs/loader.js:658:17) at require (internal/modules/cjs/helpers.js:22:18) code: 'MODULE_NOT_FOUND' }