如何在selenium webdriver中处理下载文件? [英] How to handle downloading a file in selenium webdriver?
问题描述
我是selenium的新手,我被分配了一个任务来实现下面提到的场景。
I am new to selenium and I have been assigned a task to implement below mentioned scenario.
场景:对于给定的URL,我需要进入一个网络有多个链接的页面。并且链接可以具有pdf或HTML文件。
我需要通过点击链接来下载文件,它应该通过输入excel表中的链接参考进行管理。
Scenario : For the given URL, I need to enter into one web page which is having multiple links. and the links may have either pdf or HTML files. I need to just download the files by clicking that links and it should managed by entering the links reference in excel sheets.
所以我的任务有两个挑战:
1)如何处理XL表输入值作为输入。
2)如何使用selenium下载pdf文件
So my task having two challenges:
1) how to handle XL sheet entered values as inputs.
2) how to download a pdf files using selenium
请帮我找到任何网站,我可以在哪里下载文件
Please help me finding in any site, where i can download a file
谢谢
推荐答案
Apache POI。
http://www.toolsqa.com/ selenium-webdriver / data-driven-testing-excel-poi /
Apache POI. http://www.toolsqa.com/selenium-webdriver/data-driven-testing-excel-poi/
如果您使用的是Firefox
IF you are using Firefox
使用firefox配置文件下载您的文件。这个配置文件跳过firefox的dialoge框。
在行: -
Use firefox profile to download your files. This profile skip that dialoge box of firefox. In line:-
pro.setPreference("browser.downLoad.folderList", 0);
browser.download.folderList的值可以设置为0,1或2。如果设置为0,Firefox会将通过浏览器下载的所有文件保存在用户桌面上。设置为1时,这些下载将存储在下载文件夹中。设置为2时,将再次使用为最新下载指定的位置。
The value of browser.download.folderList can be set to either 0, 1, or 2. When set to 0, Firefox will save all files downloaded via the browser on the user's desktop. When set to 1, these downloads are stored in the Downloads folder. When set to 2, the location specified for the most recent download is utilized again.
您需要实现的Firefox配置文件代码: -
Firefox profile code that you need to implement :-
FirefoxProfile pro=new FirefoxProfile();
pro.setPreference("browser.downLoad.folderList", 0);
pro.setPreference("browser.helperApps.neverAsk.saveToDisk", "Applications/zip");
WebDriver driver=new FirefoxDriver(pro);
driver.get("http://selenium-release.storage.googleapis.com/2.47/selenium-java-2.47.1.zip");
希望它能帮到你:))
这篇关于如何在selenium webdriver中处理下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!