我正在使用 Selenium 的 WebDriverJS 通过 JavaScript 自动化 Windows 8.1 上的 Chrome。我下载了 ChromeDriver 和 Selenium Standalone Server jar 文件的副本,并将其放置在 E:\Selenium
目录中。我启动了 Selenium Standalone Server 并尝试运行在 BrowserTest.js
文件中编写的 javascript 代码,并将 Node 命令提示符设置为
E:\Selenium> Node BrowserTest.js
BrowserTest.js
:
var driver = require("selenium-webdriver");
function createDriver() {
var driver = new driver.Builder()
.usingServer('http://localhost:4444/wd/hub')
.withCapabilities(driver.Capabilities.chrome())
.build();
driver.manage().timeouts().setScriptTimeout(10000);
return driver;
}
var driver = createDriver();
driver.get("http://www.google.com");
driver.getTitle().then(function (title) {
console.log(title);
});
driver.quit();
但它会抛出错误:
fs.js:500 return binding.open(pathModule._makeLong(path),
stringToFlags(flags), mode);
^ Error: ENOENT, no such file or directory 'E:\Selenium\webdriver\logging.js'
at Error (native)
at Object.fs.openSync (fs.js:500:18)
at Object.fs.readFileSync (fs.js:352:15)
at Object.Context.closure.goog.retrieveAndExecModule_ (E:\Selenium\node_modules\selenium-webdriver\_base.js:129:23)
at <anonymous>:1:6
at Object.exports.runInContext (vm.js:64:17)
at Context.closure.closure.vm.createContext.CLOSURE_IMPORT_SCRIPT (E:\Selenium\node_modules\selenium-webdriver\_base.js:101:12)
at Object.goog.importScript_ (E:\Selenium\node_modules\selenium-webdriver\lib\goog\base.js:873:9)
at Object.goog.importModule_ (E:\Selenium\node_modules\selenium-webdriver\lib\goog\base.js:894:14)
at Object.goog.writeScripts_ (E:\Selenium\node_modules\selenium-webdriver\lib\goog\base.js:1251:16)
最佳答案
更新
尝试将selenium-webdriver
版本更改为2.46.1
,它已推送到npm,并且其中的错误已修复。
就像@simon所说,this bug已经在github上报道过了,
目前,在其评论中建议了一种解决方案,
转到node_modules\selenium-webdriver\_base.js
,在100
行和101
行之间添加以下行(作为第一行如果 block ):
opt_srcText = opt_srcText.replace(/\\/g,'/');
它解决了我的问题。
关于javascript - Windows 上的 Selenium WebDriver 错误 : logging. js 未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30781209/