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

  • 相关阅读:
    js中删除数组元素的几种方法
    js中的prototype
    分布式服务框架 Zookeeper -- 管理分布式环境中的数据
    angularjs事件传递$on、$emit和$broadcast
    cron表达式
    angularjs中的时间格式化过滤
    angularjs中的$q
    IOS 错误
    Swift 错误
    IOS 控件
  • 原文地址:https://www.cnblogs.com/javalinux/p/14804331.html
Copyright © 2011-2022 走看看