Chrome网络驱动程序下载文件

编程入门 行业动态 更新时间:2024-10-09 09:23:01
本文介绍了Chrome网络驱动程序下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用的是Chrome Web Driver 2.10 chromedriver_win32.zip 与 Selenium WebDriver 2.31.2 。

启用详细日志记录后,它似乎是 DesiredCapabilities ( sites.google/a/chromium/chromedriver/capabilities )都可以通过,

[1.174] [FINE]:使用功能初始化会话{ $ bbrowserName:chrome, chrome.switches:[ ], chromeOptions:{ args:[], binary:, extensions:[], prefs:{ download.default_directory:C:\\Downloads, download.directo ry_upgrade:true, download.extensions_to_open:, download.prompt_for_download:false } }, javascriptEnabled:true, platform:WINDOWS, version : }

但Chrome Web Driver正在播放 * .mp4 而不是下载。

我在如何使用Selenium Webdriver .NET绑定设置Chrome浏览器的首选项?,但它似乎不适用于较新的Chrome网页驱动程序版本,它会崩溃,如果我尝试并使用 selenium-dotnet-2.31.2 与

解决方案

ChromeOptions options = new ChromeOptions(); 地图< String,Object> prefs = new HashMap< String,Object>(); prefs.put(profile.default_content_settings.popups,0); prefs.put(download.default_directory,getClass()。getResource(/ data / input)。toString()。replace(%20,).replace(file:, ).replaceFirst(/,)); options.setExperimentalOption(prefs,prefs); options.addArguments( - test-type); capabilities.setCapability(ChromeOptions.CAPABILITY,options);

I'm using Chrome Web Driver 2.10 chromedriver_win32.zip with Selenium WebDriver 2.31.2.

With verbose logging enabled it seems the DesiredCapabilities (sites.google/a/chromium/chromedriver/capabilities) are passed just fine,

[1.174][FINE]: Initializing session with capabilities { "browserName": "chrome", "chrome.switches": [ ], "chromeOptions": { "args": [ ], "binary": "", "extensions": [ ], "prefs": { "download.default_directory": "C:\\Downloads", "download.directory_upgrade": "true", "download.extensions_to_open": "", "download.prompt_for_download": "false" } }, "javascriptEnabled": true, "platform": "WINDOWS", "version": "" }

but Chrome Web Driver is playing *.mp4 instead of downloading.

I've tried the solution at How to set Chrome preferences using Selenium Webdriver .NET binding? but it doesn't seem to work with newer Chrome Web Driver version, and it crashes if i try and use selenium-dotnet-2.31.2 with chromedriver_win_26.0.1383.0.

Anybody has a suggestion?

解决方案

ChromeOptions options = new ChromeOptions(); Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("profile.default_content_settings.popups", 0); prefs.put("download.default_directory", getClass().getResource("/data/input").toString().replace("%20", " ").replace("file:","").replaceFirst("/", "")); options.setExperimentalOption("prefs", prefs); options.addArguments("--test-type"); capabilities.setCapability(ChromeOptions.CAPABILITY, options);

更多推荐

Chrome网络驱动程序下载文件

本文发布于:2023-11-27 16:18:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638715.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序下载   文件   网络   Chrome

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!