2014-07-22 88 views
1

我使用Express創建了一個項目,現在我嘗試使用Phantomjs運行硒代碼。Selenium with PhantomJs和NodeJs

我:

var app = express(); 

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

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

但是當我嘗試運行我有這個錯誤:

path/node_modules/selenium-webdriver/phantomjs.js:72 
    throw Error(
     ^
Error: The PhantomJS executable could not be found on the current PATH. Please download the latest version from http://phantomjs.org/download.html and ensure it can be found on your PATH. For more information, see https://github.com/ariya/phantomjs/wiki 
    at Error (<anonymous>) 
    at findExecutable (/home/antonio/node_modules/selenium-webdriver/phantomjs.js:72:11) 
    at Object.createDriver (/home/antonio/node_modules/selenium-webdriver/phantomjs.js:108:13) 
    at createNativeDriver (/home/antonio/node_modules/selenium-webdriver/builder.js:43:24) 
    at Builder.build (/home/antonio/node_modules/selenium-webdriver/builder.js:96:18) 
    at Object.<anonymous> (/home/antonio/projectNode/ExpressProject/app.js:18:4) 
    at Module._compile (module.js:456:26) 
    at Object.Module._extensions..js (module.js:474:10) 
    at Module.load (module.js:356:32) 
    at Function.Module._load (module.js:312:12) 
+0

你安裝了phantomjs包嗎? –

+0

是的,我安裝phantomjs幻影;硒webdriver和webdriverjs – FelasDroid

+1

然後,你必須運行你的硒驅動程序web驅動器管理器啓動 你可以參考以下鏈接手動修復路徑http://code.tutsplus.com/tutorials/headless -functional-testing-with-selenium-and-phantomjs -net-30545 –

回答

0

您需要安裝幻影JS包您滿意OS,我對Ubuntu的,所以我做這個

sudo apt-get install phantomjs 

並且這個錯誤消失了,如果你已經安裝了phantomjs包,那麼你的路徑settin出錯了gs,爲幻象設置路徑變量