我学习Selenium Webdriver。我无法使用导入类运行脚本,但我可以在没有类的情况下运行它,只需使用导入功能。我和babel-cli一样运行它node ./babel-cli/bin/babel-node.js --presets node6 ./test.js
//test.js
import homePage from "./home_page"
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
home_page = new homePage(driver);
home_page.go_home_page();
//home_page.js
export default class homePage{
constructor(driver){
this.driver = driver;
}
go_home_page = function(){
this.driver.get("https://www.google.com/");
}
}
错误是:home_page.js: Unexpected token (5:15)
答案 0 :(得分:1)
节点最初为built with CommonJS modules,并且已过渡到ES2015模块will not be easy。
您的示例同时使用两者:import
是ES2015,require
是CommonJS。如果您将import
更改为require
则应该有效。
import
的CommonJS等价物如下所示:
var homePage = require('./home_page');
答案 1 :(得分:-1)