-2

我無法在selenium網絡驅動程序中使用driver.get(「URL」)打開網址。我無法在selenium網絡驅動程序中使用driver.get(「URL」)打開網址

我的Firefox版本是53.0.3和selenium 3.4.0。

我的代碼是:

System.setProperty("webdriver.gecko.driver","D:\\geckodriver-v0.16.1-win64\\geckodriver.exe"); 
    WebDriver driver = new FirefoxDriver(); 
    driver.get("url"); 

它給了我下面的錯誤:

1496135300464 geckodriver INFO Listening on 127.0.0.1:8753 
    1496135301127 geckodriver::marionette INFO Starting browser \\?\C:\Program Files\Mozilla Firefox\firefox.exe with args ["-marionette"] 
1496135301419 addons.manager ERROR startup failed: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIFile.create]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: resource://gre/modules/FileUtils.jsm :: FileUtils_getDir :: line 70" data: no] Stack trace: FileUtils_getDir()@resource://gre/modules/FileUtils.jsm:70 < FileUtils_getFile()@resource://gre/modules/FileUtils.jsm:42 < validateBlocklist()@resource://gre/modules/AddonManager.jsm:671 < startup()@resource://gre/modules/AddonManager.jsm:834 < startup()@resource://gre/modules/AddonManager.jsm:3129 < observe()@resource://gre/components/addonManager.js:65 
JavaScript error: resource://gre/modules/AddonManager.jsm, line 1657: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized 
JavaScript error: resource://gre/components/SanityTest.js, line 65: NS_ERROR_FILE_ACCESS_DENIED: Component returned failure code: 0x80520015 (NS_ERROR_FILE_ACCESS_DENIED) [nsIPrefService.savePrefFile] 
JavaScript error: resource://gre/modules/AddonManager.jsm, line 2570: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized 
JavaScript error: resource://gre/modules/FileUtils.jsm, line 70: NS_ERROR_ILLEGAL_VALUE: Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIFile.create] 
JavaScript error: resource://app/modules/WindowsJumpLists.jsm, line 403: NS_ERROR_FILE_NOT_FOUND: Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIJumpListShortcut.app] 
JavaScript error: resource://app/modules/WindowsJumpLists.jsm, line 403: NS_ERROR_FILE_NOT_FOUND: Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIJumpListShortcut.app] 
JavaScript error: resource://app/modules/WindowsJumpLists.jsm, line 403: NS_ERROR_FILE_NOT_FOUND: Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIJumpListShortcut.app] 
+0

嘗試使用geckodriver v0.16.0應該解決這個問題 – mosaad

回答

0

夫婦的事情。而不是「網址」,它應該是一些像「http://www.google.com」的實際網址。另外,您可能還需要提供moz:firefoxOptions.binary。檢查下面的代碼以供參考 -

FirefoxOptions options = new FirefoxOptions(); 
options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); //Location where Firefox is installed 

DesiredCapabilities capabilities = DesiredCapabilities.firefox(); 
capabilities.setCapability("moz:firefoxOptions", options); 

FirefoxDriver driver = new FirefoxDriver(capabilities); 
driver.get("http://www.google.com"); 

有關設置的詳細信息,你可以參考這篇文章 - Launch Firefox with GeckoDriver

+0

我只有用實際的URL,但對於後我已經使用'網址'。感謝您的快速回復 –

+0

Okie ..添加moz:firefoxOptions是否適合您? –

+0

是的。這個對我有用。 –

相關問題