如何使用Selenium Webdriver下载任何文件并将其保存到所需位置 [英] How to download any file and save it to the desired location using Selenium Webdriver

查看:989
本文介绍了如何使用Selenium Webdriver下载任何文件并将其保存到所需位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用下面给出的Selenium Webdriver执行以下任务.

I have to perform following task using Selenium Webdriver given below.

  1. 单击任何开始下载任何文件的链接/按钮(文件类型可以是图像,pdf,jar等)
  2. 单击弹出窗口上的保存"(如果显示)(例如任何人都可以共享,我们如何使用Java来实现呢?

    Can anyone share, how can we implement this using Java?

    推荐答案

    您将无法访问保存对话框.这是由操作系统控制的.您真正唯一能够做的就是为浏览器设置默认的下载位置,并允许它自动下载文件.然后用Java检查文件.

    You won't be able to access the save dialog box. That's controlled by the OS. The only thing you're really going to be able to do is set the default download location for the browser and allow it to automatically download the files. Then check the file in Java.

    您应该从

    You should check this answer from this previous SO question. Basically when setting up your Firefox profile you add a call to set the property browser.helperApps.neverAsk.saveToDisk to a comma separated list of MIME types to always download:

    firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv");
    

    有关About:configs,请参见此Mozilla KB FAQ文章.

    See this Mozilla KB FAQ article on About:configs.

    更新 看来现在可能有可能在另一个问题中看到这个答案

    UPDATE It looks like this may now be possible see this answer in another question

    这篇关于如何使用Selenium Webdriver下载任何文件并将其保存到所需位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆