SyntaxError:运行Selenium-JavaScript测试时出现意外令牌

时间:2018-09-09 08:59:19

标签: javascript node.js selenium npm webdriver

多年来我一直在与Java做硒。但是,现在我正在尝试使用javascript编写Selenium脚本。我使用以下指南来学习Selenium的JavaScript。

Guide

但是,当我在命令提示符下尝试npm install selenium-webdriver@3.6时,显示以下错误。

npm WARN saveError ENOENT: no such file or directory, open 'E:\Proffessional\FMClarity\Selenium\package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'E:\Proffessional\FMClarity\Selenium\package.json'
npm WARN Selenium No description
npm WARN Selenium No repository field.
npm WARN Selenium No README data
npm WARN Selenium No license field.

+ selenium-webdriver@3.6.0
added 30 packages from 69 contributors and audited 34 packages in 8.086s
found 0 vulnerabilities

然后我尝试遵循以下简单脚本,

var webdriver = require('selenium-webdriver');

var driver = new webdriver.Builder().
                           withCapabilities(webdriver.Capabilities.firefox() 
                            .build();

driver.get('https://github.com/i18next/i18next-parser/issues/86');

我尝试使用node sample.js运行此脚本。 但是出现以下错误,

SyntaxError: Unexpected token <
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

这可能不是一个很好的问题。但是,即使我有多年Java经验,我还是JavaScript的新手。

任何形式的帮助都将不胜感激 提前致谢。 :)

1 个答案:

答案 0 :(得分:2)

似乎您缺少该行中的结尾 )

var driver = new webdriver.Builder().
               withCapabilities(webdriver.Capabilities.firefox() 
                .build();

将其更改为:

var driver = new webdriver.Builder().
               withCapabilities(webdriver.Capabilities.firefox()) 
                .build();