1

我使用Selenium的WebDriverJS以JavaScript自動化Windows 8.1上的Chrome。我下載了ChromeDriver和Selenium Standalone Server jar文件的副本,並將其放在E:\Selenium目錄中。我開始硒獨立服務器,並試圖運行用BrowserTest.js文件與節點命令提示符我的javascript代碼Windows上的Selenium WebDriver錯誤:logging.js not found

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) 

回答

0

問題已通過更新至版本解決 - 2.46.1

0

在Windows上Selenium的v2.46.0中似乎有一個bug

它剛剛被固定在2.46.1,所以如果你更新它應該解決您的問題

1

更新

嘗試改變selenium-webdriver2.46.1,它一直推到NPM和它,錯誤已被修復。


像@simon說,this bug已經被報道在github上,

現在,一個黑客已經被建議作爲它的評論的解決方案,

node_modules\selenium-webdriver\_base.js之間添加下面一行線100和線101(彷彿塊的第一行):

opt_srcText = opt_srcText.replace(/\\/g,'/'); 

它固定對我來說這個問題。