admin 管理员组

文章数量: 887021

public void setup() {
		System.setProperty("webdriver.chrome.driver",
				"D:/software/Performance Test/Selenium/ChromeDriver/chromedriver_win32/chromedriver.exe");
		DesiredCapabilities caps = setDownloadsPath();// 更改默认下载路径
		driver = new ChromeDriver(caps);
		ChromeOptions options = new ChromeOptions();
		options.addArguments("user-data-dir=C:/Users/acer/AppData/Local/Google/Chrome/User Data");
		baseUrl = "http://114.91.125.84:9030/";
		driver.get(baseUrl);
		driver.manage().window().maximize();
		driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
	}


/ 封装一个设置下载文件保存的路径
	public DesiredCapabilities setDownloadsPath() {
		String downloadsPath = "D:\\outputReport\\Downloads";
		HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
		chromePrefs.put("download.default_directory", downloadsPath);
		ChromeOptions options = new ChromeOptions();
		options.setExperimentalOption("prefs", chromePrefs);
		DesiredCapabilities caps = new DesiredCapabilities();
		caps.setCapability(ChromeOptions.CAPABILITY, options);
		return caps;
	}

 这样点击下载后发现现在的文件就保存在downLoadPath所在的路径下

 

本文标签: 路径 浏览器 文件 selenium java