question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't use WebDriver grab methods - unexpected identifier

See original GitHub issue

I’m using Selenium and Firefox. I’m trying to use I.grabTextFrom or I.grabAttributeFrom, and I get the error:

CodeceptJS v0.3.3
Test root is assumed to be /Users/andrew/code/myapp

Unexpected identifier

SyntaxError:
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:404:25)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at /Users/andrew/.nvm/versions/node/v5.1.1/lib/node_modules/codeceptjs/node_modules/mocha/lib/mocha.js:219:27
    at Array.forEach (native)
    at Mocha.loadFiles (/Users/andrew/.nvm/versions/node/v5.1.1/lib/node_modules/codeceptjs/node_modules/mocha/lib/mocha.js:216:14)

I’ve defined an element in my dom, with an id ‘test’, and a value ‘foo’:

<div id="test">Foo</div>

And I try to grab the value:

    var test = yield I.grabTextFrom('#test');

This causes the above error. Not sure why.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
neil-scommented, Jun 25, 2016

@andrewhl , I’ve figured out the reason, at least for my instance of the bug, and it’s entirely user error. When I RTFM, I realized that I wasn’t using a generator function for the scenario. From the documentation:

All actions starting with grab prefix are expected to return data. In order to synchronize this step with a scenario you should pause test execution with yield keyword of ES6. To make it work your test should be written inside a generator function (notice * in its definition):

Scenario('use page title', function*(I) {
  // ...
  var password = yield I.grabTextFrom('#password');
  I.fillField('password', password);
});

Without it being a generator function, that yield keyword is nonsense to the JS engine, hence the unknown identifier error.

2reactions
neil-scommented, Jun 24, 2016

I am reproducing this same error.

Feature('Hello');

Scenario('test something', (I) => {
    I.amOnPage('/');
    var title = yield I.grabTitle();
});
{
  "tests": "./*_test.js",
  "timeout": 10000,
  "output": "./output",
  "helpers": {
    "WebDriverIO": {
      "url": "http://www.google.com",
      "browser": "chrome"
    }
  },
  "include": {
    "I": "./steps_file.js"
  },
  "bootstrap": false,
  "mocha": {},
  "name": "somename"
}

So simply going to Google and getting the title causes this issue. Removing the grabTitle line makes the error go away. Stacktrace is the same as OP.

Unexpected identifier

SyntaxError:
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at C:\Users\Neil\AppData\Roaming\nvm\v4.4.5\node_modules\codeceptjs\node_modules\mocha\lib\mocha.js:220:27
    at Array.forEach (native)
    at Mocha.loadFiles (C:\Users\Neil\AppData\Roaming\nvm\v4.4.5\node_modules\codeceptjs\node_modules\mocha\lib\mocha.js:217:14)

Versions: Codecept: 0.3.5 Node: 4.4.5 Windows: 10

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't use WebDriver grab methods - unexpected identifier #111
I'm using Selenium and Firefox. I'm trying to use I.grabTextFrom or I.grabAttributeFrom, and I get the error: CodeceptJS v0.3.3 Test root is ...
Read more >
Unexpected identifier in selenium-webdriver/lib/http.js:454 ...
I ran into this issue. Run node -v if your version is under 8 it doesn't have the ability to handle the async...
Read more >
JavascriptExecutor SyntaxError: Unexpected identifier. Why?
All syntax errors should be gone, but I still get "SyntaxError: Unexpected identifier". What this code is trying to do is wait for...
Read more >
T236282 `npm run selenium` fails on MW Vagrant (SyntaxError
`npm run selenium` fails on MW Vagrant (SyntaxError: Unexpected identifier; due to Node 6). Closed, DuplicatePublic.
Read more >
Working with windows and tabs - Selenium
If not running WebDriver in a test context, you may consider using try / finally which is offered by most languages so that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found