【发布时间】:2019-05-15 11:13:51
【问题描述】:
从网站下载 xml 文件并存储在所需位置(带有 chrome 浏览器的 java / selinium)
下面是html代码
<!-- Start of Code which handles XML Download-->
<a href="javascript:downloadXML()">
<img src="/img/tabs/downloadxml.gif" alt="Download" name="imag34" width="40" height="20" border="0">
</a>
<!-- End of Code which handles XML Download-->
首先,单击图像,文件应自动存储在我想要的位置
下面是我的 chrome 配置
File file = new File("resources/chromedriver.exe");
String downloadFilepath = "mydownload path";
Map<String, Object> preferences = new Hashtable<>();
String absolutePath = file.getAbsolutePath();
System.setProperty("webdriver.chrome.driver", absolutePath);
preferences.put("profile.default_content_settings.popups", 0);
preferences.put("download.prompt_for_download", "false");
preferences.put("download.default_directory", downloadFilepath);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", preferences);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
执行
while clicking the image the xml file downloaded in my desired location with 0kb size
问题: 为什么文件没有完全下载?我的代码有什么错误吗?
【问题讨论】:
标签: javascript java google-chrome selenium-webdriver selenium-chromedriver