3
只想學習以自己的樣本開始的Selenium測試。 然而,一切都建立後(Node.js,Selenium),當我想使用硒-webdriver自己的示例,它不工作:無法在selenium 3.0-beta3中使用geckodriver 0.10在selenium自己的示例中使用Javascript啓動Firefox
這是官方代碼(名稱是google_search.js)提供硒:
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
driver.get('http://www.google.com/ncr');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.findElement(By.name('btnG')).click();
driver.wait(until.titleIs('webdriver - Google Search'), 1000);
driver.quit();
此代碼是example
文件夾中,在Node.js的CMD,我cd到node_modules \硒webdriver的\例如,把geckodriver此文件夾中,然後運行node google_search.js
這裏的結果:
C:\Users\username\node_modules\selenium-webdriver\lib\promise.js:2291
throw error;
^
WebDriverError: Unable to parse new session response: {"error":"unknown error","
message":"Expected browser binary location, but unable to find binary in default
location, no 'firefox_binary' capability provided, and no binary flag set on th
e command line"}
at WebDriverError (C:\Users\username\node_modules\selenium-webdriver\lib\err
or.js:27:10)
at C:\Users\username\node_modules\selenium-webdriver\lib\http.js:335:17
at process._tickCallback (node.js:369:9)
From: Task: WebDriver.createSession()
at Function.createSession (C:\Users\username\node_modules\selenium-webdriver
\lib\webdriver.js:366:24)
at createGeckoDriver (C:\Users\username\node_modules\selenium-webdriver\fire
fox\index.js:497:27)
at Driver (C:\Users\username\node_modules\selenium-webdriver\firefox\index.j
s:605:14)
at Builder.build (C:\Users\username\node_modules\selenium-webdriver\index.js
:557:16)
at Object.<anonymous> (C:\Users\username\node_modules\selenium-webdriver\exa
mple\google_search.js:44:6)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
From: Task: WebDriver.navigate().to(http://www.google.com/ncr)
at Driver.schedule (C:\Users\username\node_modules\selenium-webdriver\lib\we
bdriver.js:414:17)
at Navigation.to (C:\Users\username\node_modules\selenium-webdriver\lib\webd
river.js:1042:25)
at Driver.get (C:\Users\username\node_modules\selenium-webdriver\lib\webdriv
er.js:832:28)
at Object.<anonymous> (C:\Users\username\node_modules\selenium-webdriver\exa
mple\google_search.js:46:8)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
我做錯了什麼嗎?誰能告訴我爲什麼官方樣本不啓動Firefox?謝謝!
http://stackoverflow.com/questions/9907492/how-to-get-firefox-working-with-selenium-webdriver-on-mac-osx - 檢查這 – Rao