selenium WebDriver处理文件下载

下载文件
WebDriver 允许我们设置默认的文件下载路径。也就是说文件会自动下载并且存在设置的那个目录
中。下面以FireFox 为例执行文件的下载。

package com.mypro.jase;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
public class download {
public static void main(String[] args){
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.download.folderList",2); //设置成0 代表下载到浏览器默认下载路径;设置成2 则可以保存到指定目录。
firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false); //是否显示开始,Ture 为显示,Flase 为不显示。
firefoxProfile.setPreference("browser.download.dir","d:\\java");   //用于指定你所下载文件的目录。
firefoxProfile.setPreference(
"browser.helperApps.neverAsk.saveToDisk","application/octet-stream");
//指定要下载页面的Content-type 值,“application/octet-stream”为文件的类型 WebDriver driver = new FirefoxDriver(firefoxProfile); driver.get("https://pypi.Python.org/pypi/selenium"); driver.findElement(By.partialLinkText("selenium-2")).click(); } }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值