zoukankan      html  css  js  c++  java
  • selenium + Java 设置文件默认下载路径

    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

  • 相关阅读:
    4.23上机练习
    4.17java作业
    4.16java作业
    leetcode 189
    leetcode 172
    leetcode 171
    leetcode 169
    win10内网外网智能访问
    leetcode 168
    leetcode 165
  • 原文地址:https://www.cnblogs.com/javalinux/p/14804331.html
Copyright © 2011-2022 走看看