webdriver操作火狐浏览器的属性配置

package com.gloryroad.Demo;


import org.junit.Before;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;


public class DownLoadFile {
public static String downloadFilePath="C:\\Doload";
WebDriver driver;
String baseUrl;
JavascriptExecutor js;
@BeforeMethod
public void beforeMethod(){
baseUrl="http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/35.0b8/win32/zh-CN";



}
@AfterMethod
public void afterMethod(){

driver.quit();
}

@Test
public void testdataPicker(){
driver=new FirefoxDriver(FirefoxDriverProfile());
driver.get(baseUrl);




}

public static FirefoxProfile FirefoxDriverProfile(){
FirefoxProfile profile=new FirefoxProfile();
//设定为0则会下载到桌面,设定为2则会表示下载到用户的桌面上
profile.setPreference("browser.download.folderList", 2);
//设置为true表示下载的时候显示火狐浏览器文件下载窗口,设置false表示不显示
profile.setPreference("browser.download.manager.showWhenStarting", false);
//设定下载的文件的存储位置
profile.setPreference("browser.download.dir",downloadFilePath);
//完成提示框,默认为true,设定为false表示下载完成后不显示下载完成的提示框
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
//设定下载结束后是否自动关闭下载管理器默认为true,
profile.setPreference("browser.download.manager.closeWhenDone", false);
//让用户处理默认为true,设定为false,表示不会记录打开位置的MIKE类型的文件
profile.setPreference("browser.helperApps.alwaysAsk.froce", false);
//下载。exe文件弹出警告框,默认是true,设定为false则不会弹出来
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
//设定下载框在下载时会获取焦点,默认为true,设为false
profile.setPreference("browser.download.manager.focusWhenStarting", false);
//设定下载时是否显示下载框,默认为true,设为false
profile.setPreference("browser.download.manager.useWindow",false);
//不提示,直接下载文件
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "appliction/pdf");
return profile;



}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值