javascript - Windows 上的 Selenium WebDriver 错误 : logging. js 未找到

标签 javascript node.js selenium selenium-webdriver selenium-chromedriver

我正在使用 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/

相关文章:

javascript - 如何自动删除 NodeJs 中超过一周的所有记录/行?

javascript - AddEventListener 在分配时自动触发

node.js - ejs模板的客户端和服务器端渲染

node.js - next() 在 Express 4 中不起作用

python - 无法在 chrome 上通过 id 查找元素

javascript - 我可以通过标准 Javascript 应用程序使用 Google Polymer 吗?

javascript - 如何在 div 中插入 java 脚本函数的元素?

node.js - 无法使用 ionic 或 cordova

java - Selenium 网络驱动程序 : getText() returning empty String for h2 tag

java - 如何在 Selenium-Java Webdriver 测试项目中指定 Java 类的执行顺序