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

  • 相关阅读:
    java MVC设计模式探究——mvc在JAVA应用程序中的应用
    datagridview 的Columns 点击列标题 禁止排序
    组合键事件
    对一段视频,采帧(总结)
    datagridview中加入checkbox列,全选问题
    微软的RDLC报表(转)
    Linq to sql直接执行sql语句(转)
    获取当月的第1天
    AxWindowsMediaPlayer的详细用法
    DataSet
  • 原文地址:https://www.cnblogs.com/javalinux/p/14804331.html
Copyright © 2011-2022 走看看