Change default download location on Edge chromium

前端 未结 1 672
隐瞒了意图╮
隐瞒了意图╮ 2021-01-25 03:39

I would like to ask if someone has tried to change the default download location on Microsoft Edge Chromium driver using selenium 3.X. On Chrome browser, we could use something

相关标签:
1条回答
  • 2021-01-25 03:59

    Try using the following setup (Java Bindings):

    public WebDriver newDriver() {
    
        try {
    
            EnvironmentVariables vars = SystemEnvironmentVariables.createEnvironmentVariables();
    
            String version = vars.getProperty("webdriver.edgedriver.version");
            WebDriverManager.edgedriver().version(version).setup();
    
            EdgeOptions options = new EdgeOptions();
    
            EdgeDriverService edgeDriverService = EdgeDriverService.createDefaultService();
    
            EdgeDriver edgeDriver = new EdgeDriver(edgeDriverService, options);
    
            final String downloadPath = ${your path}
    
            //************* Enable downloading files / set path *******************
            Map<String, Object> commandParams = new HashMap<>();
            commandParams.put("cmd", "Page.setDownloadBehavior");
            Map<String, String> params = new HashMap<>();
            params.put("behavior", "allow");
            params.put("downloadPath", downloadPath);
            commandParams.put("params", params);
            ObjectMapper objectMapper = new ObjectMapper();
            HttpClient httpClient = HttpClientBuilder.create().build();
            String command = objectMapper.writeValueAsString(commandParams);
            String u = edgeDriverService.getUrl().toString() + "/session/" + edgeDriver.getSessionId() + "/chromium/send_command";
            HttpPost request = new HttpPost(u);
            request.addHeader("content-type", "application/json");
            request.setEntity(new StringEntity(command));
            httpClient.execute(request);
    
            return edgeDriver;
    
        } catch (Exception e) {
            throw new Error(e);
        }
    }
    

    I was able to download files to the desired path using this snippet. Source here

    0 讨论(0)
提交回复
热议问题