2013-06-19 40 views

回答

2

最簡單的方法是設置讓你的測試使用一個設置爲自動接受下載提示的firefox配置文件。請參閱here以獲取幫助以創建新配置文件。要在測試中使用此配置文件,請參閱here問題的最佳答案。不過,我也推薦閱讀this,這將解釋爲什麼你實際上不需要下載文件來測試你的下載功能是否正常工作。

+0

解釋爲什麼不需要下載文件的鏈接已經死亡。它現在位於此處:http://ardesco.lazerycode.com/testing/webdriver/2012/07/25/how-to-download-files-with-selenium-and-why-you-shouldnt.html – Scone

3

您可以嘗試使用下面的代碼,下載zip文件:

FirefoxProfile profile = new FirefoxProfile(); 
//MIME type for zip file "application/zip" 

profile.setPreference("browser,helperapps.neverAsk.SaveToDisk", "application/zip"); 

// 0 = desktop, 1 = default download folder , 2 = user defined location. 
profile.setPreference("browser.download.folderList",0); 

driver = new FirefoxDriver(profile); 
baseUrl = " http://www.yourwebsite.com "; 
driver.get(baseUrl); 
driver.findElement(By.id("downloadFile")).click; 
0

你爲什麼不選擇Sikuli,實在是太簡單了。
在構建路徑中添加sikuli-java.jar文件,安裝Picpick軟件,使用Picpick保存保存文件的圖像,確定按鈕。
鍵入以下命令

new Screen().click(new Pattern("E:\\simage\\save.png")); //here e:\\..is image file path 
new Screen().click(new Pattern("E:\\simage\\ok.png")); 

一切都結束了。

-1

是sikuli是針對簡單的解決方案,你可以使用

相關問題