[英]Selenium java file download not working on Chrome ver 75
I am facing an issue with download file from Google chrome version 75.0.3770.80
with Selenium Java, it displays Failed - Download Error我在使用 Selenium Java 从 Google chrome 75.0.3770.80
版下载文件时遇到问题,它显示失败 - 下载错误
I've tried to change the download path and then download the file, the path does get set but no luck.我试图更改下载路径然后下载文件,路径确实设置但没有运气。
Below is sample code :以下是示例代码:
WebDriver webDriver;
System.setProperty ("webdriver.chrome.driver",
SetObjectProperties.appConfig.
getPropertyValue ("ChromeDriver"));
String currentDir = System.getProperty ("user.dir");
String downloadpath = currentDir + "/" + "Download";
HashMap < String, Object > chromePrefs =
new HashMap < String, Object > ();
chromePrefs.put ("profile.default_content_settings.popups", 0);
chromePrefs.put ("download.prompt_for_download", false);
chromePrefs.put ("download.default_directory", downloadpath);
chromePrefs.
put
("profile.content_settings.exceptions.automatic_downloads.*.setting",
1);
ChromeOptions options = new ChromeOptions ();
options.setExperimentalOption ("prefs", chromePrefs);
options.addArguments ("--incognito");
webDriver = new ChromeDriver (options);
webDriver.manage ().window ().maximize ();
webDriver.get ("http://www.seleniumhq.org/download/");
webDriver.findElement (By.linkText ("32 bit Windows IE")).click ();
如果你在 Windows 上运行试试这个它对我有用。
String downloadpath = currentDir + "\\" + "Download";
删除此行后尝试
chromePrefs.put ("download.default_directory", downloadpath);
I was also facing this issue which is resolve by using below solution :-我也遇到了这个问题,可以通过使用以下解决方案来解决:-
String currentDir = System.getProperty("user.dir");
String downloadpath = currentDir + "/" + "Download";
chromePrefs.put("download.default_directory", downloadpath);
Try setting downloadpath as below:尝试设置下载路径如下:
String downloadFilepath = System.getProperty("user.dir")+ File.separator +"Download"; String downloadFilepath = System.getProperty("user.dir")+ File.separator +"Download";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.