2013-02-18 85 views
0

我嘗試使用該配置文件的設置下載文件在Firefox,但它不工作,你能告訴我什麼,我做錯了,我使用的代碼被髮布這條線爲什麼我無法使用Selenium Webdriver通過Firefox下載文件?

var profile = new FirefoxProfile { EnableNativeEvents = true }; 
profile.SetPreference("browser.download.folderList", 2); 
profile.SetPreference("browser.download.manager.showWhenStarting", false); 
profile.SetPreference("browser.download.dir", folderName); 
profile.SetPreference("browser.download.downloadDir", folderName); 
profile.SetPreference("browser.download.defaultFolder", folderName); 
profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "image/jpeg,application/vnd.oasis.opendocument.text,application/vnd.oasis.opendocument.spreadsheet," + 
                      "application/vnd.oasis.opendocument.presentation,application/vnd.oasis.opendocument.graphics," + 
                      "application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet," + 
                      "application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation," + 
                      "application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.mozilla.xul+xml," + 
                      "application/vnd.google-earth.kml+xml"); 
+0

那麼它不起作用? – Arran 2013-02-18 15:51:42

+0

它不會自動下載文件,我仍然在獲取文件下載窗口 – 2013-02-18 15:53:28

+0

作爲臨時的解決方法,我可以使用AutoIT腳本。 – Hemanth 2013-02-19 06:16:26

回答

0

硒下面創建一個新的Firefox每次運行的配置文件。您將需要爲硒創建一個firefox配置文件並讓您的硒腳本使用它。如果你在這個配置文件上設置自動下載,那麼它應該工作得很好!

看到這裏 http://girliemangalo.wordpress.com/2009/02/05/creating-firefox-profile-for-your-selenium-rc-tests/

我只做到了這一點對於Java,但我想的方法是相似的。

編輯 Java代碼中指定配置是:

ProfilesIni profile = new ProfilesIni(); 
FirefoxProfile ffprofile = profile.getProfile("SELENIUM"); 
WebDriver driver = new FirefoxDriver(ffprofile); 

來源:

What profile does Selenium WebDriver use by default?

+0

它每次創建一個新的空白配置文件,不是?唯一可以讓我記住我的偏好的方法是通過預定義的配置文件。 – confusified 2013-04-11 10:08:05

1

花費幾天的時間,閱讀大量的可能性之後,這個工作對我來說如此我與你分享,我希望它可以是有用的: 我只是這樣設置webdriver firefox個人資料:

firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream doc xls pdf txt"); 

該解決方案允許我避免顯示firefox下載彈出窗口,並且可以使用selenium webdriver自動下載XLS文件。

相關問題