import java.util.HashMap;
import java.util.Map;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Test {
public static void main(String[] args) throws InterruptedException {
//谷歌瀏覽器
System.setProperty(“webdriver.chrome.driver”,
“C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe”);
DesiredCapabilities caps = setDownloadsPath(“D:\\DownLoad”);//更改默认下载路径
WebDriver webDriver = new ChromeDriver(caps);
}
/**
* 设置默认下载路径
* @param path
* @return
*/
public static DesiredCapabilities setDownloadsPath(String path) {
Map<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put(“download.default_directory”, path);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption(“prefs”, chromePrefs);
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(ChromeOptions.CAPABILITY, options);
return caps;
}
}
————————————————
版权声明:本文为CSDN博主「辛勤小王子」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_37917691/article/details/106945429