簡體   English   中英

下載文件存儲位置和處理使用帶有JAVA的selenium webdriver下載彈出窗口

[英]download file stored Location and handling Download Popup using selenium webdriver with JAVA

請通過以下幾點實施建議

1.如何使用Selenium Webdriver和JAVA一起處理IE中的下載彈出窗口? 想保存那個Xml文件

2.如何使用JAVA將xml文件存儲在不同的位置?

注意:我們將傳遞'n'個輸入,每個輸入都有一個xml文件,需要所有xml文件下載並保存在不同的位置

我建議你不要使用selenium自動下載文件。 這是一個你不想墮落的陷阱。 文件下載在不同的瀏覽器中有不同的 人們會建議使用AutoIT,但它只適用於Windows,因此無法進行跨平台測試。 由於您使用Java綁定,因此可以使用Robot類將鼠標指針移動到窗口上的某個位置並發送本機單擊。 根據我的經驗,這個解決方案真的很不穩定。 您不知道必須單擊的確切位置,而使用Robot時,您會盲目地點擊某些內容。 除此之外,當您使用selenium網格在遠程計算機上運行測試時,事情變得更加困難。

那么你如何下載文件? 只需獲取底層鏈接即可下載DOM中可用的文件並觸發GET請求。 如果要驗證文件,請下載內容。 如果您不想驗證內容,只需回復代碼即可。 是一個很棒的博客,上面有關於如何使用http請求在后台下載文件的Java示例,以及為什么使用selenium下載文件的詳細解釋是一個壞主意。

在初始化驅動程序對象之前,嘗試在DesiredCapabilityObject中設置以下首選項集 -

File ffProfileFolder = new File("." + File.separator + "src" + File.separator
                    + "test" + File.separator + "resources" + File.separator + "FFProfiles" + File.separator + "AutoUser" + File.separator);
File workspacePath = new File(".."+File.separator);
String workspaceCanPath = workspacePath.getCanonicalPath();
String downloadDir = workspaceCanPath+File.separator+"Downloads";
OSInteractions.createDir(downloadDir);

profileAutoUser.setPreference("browser.download.manager.showWhenStarting",false);
profileAutoUser.setPreference("browser.download.dir",downloadDir);
profileAutoUser.setPreference("browser.download.defaultFolder",downloadDir);
profileAutoUser.setPreference("browser.download.lastDir",downloadDir);
profileAutoUser.setPreference("browser.download.folderList",2);
profileAutoUser.setPreference("browser.download.useDownloadDir",true);
profileAutoUser.setPreference("browser.helperApps.neverAsk.saveToDisk","application/octet-stream,application/msexcel");

DesiredCapabilities capFF = DesiredCapabilities.firefox();
capFF.setCapability(FirefoxDriver.PROFILE, profileAutoUser);


driver = new FirefoxDriver(profileAutoUser);

請注意,這僅適用於FF。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM