0
我目前正在使用Selenium从我们校园周围的几十台MFD打印机中提取一些数据,并且它大部分都很顺利。我可以登录,点击菜单,并下载文件到我设置的位置。我需要做的是依次登录到每台打印机并将相同的文件下载到不同的文件夹。到目前为止,相关的代码如下所示:使用Selenium和Java将多个文件下载到多个位置
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>();
options.setExperimentalOption("prefs", chromePrefs);
options.addArguments("--test-type");
cap.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap);
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
webDriver = new ChromeDriver(cap);
wait = new WebDriverWait(webDriver, 20);
String fileName = "Y:/MFDAutomationEnv/test_mfd_list.txt";
readFile(fileName);
if(fileData == null){
logPrint("Couldn't read from " + fileName);
return;
}
for(int currentMFD = 0; currentMFD < fileData.length; currentMFD++){
//navigate
mfdDownloadButton(ip);
mfdLogout(ip);
}
private static int mfdDownloadButton(String ip){
try{
chromePrefs.put("download.default_directory", downloadFilepath + "someSubDirectory/");
wait.until(ExpectedConditions.elementToBeClickable(By.id("btnEXE"))).click();
}
catch(Exception e){
logPrint("Failed to find download button for " + ip);
return 1;
}
return 0;
}
因此,基本上,有没有办法来改变在运行中下载位置,而无需重新实例一个全新的webdriver?