[英]i am using Selenium web driver and using chrome with with i want to set download location but failed
String desktopPath =System.getProperty("user.home") + "\\"+"Desktop";
String s = desktopPath.replace("\\","\\\\") ;
System.out.print(s);
System.setProperty("webdriver.chrome.driver","C:\\Users\\WaqaeAbbas\\Downloads\\Compressed\\chromedriver_win32\\chromedriver.exe");
String downloadFilepath = s;
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", "C:\\Users\\WaqaeAbbas\\Desktop");
ChromeOptions options = new ChromeOptions();
HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>();
options.setExperimentalOption("prefs", chromePrefs);
options.addArguments("--test-type");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap);
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(cap);
如果我們給出“\\\\”,它就不起作用。 因此,當我們像這樣傳遞下載路徑時它正在工作: String desktopPath ="C:/Users/WaqaeAbbas/Desktop";
這是更新后的代碼:
String desktopPath ="C:/Users/WaqaeAbbas/Desktop";
System.out.print(desktopPath);
System.setProperty("webdriver.chrome.driver","C:\\Users\\WaqaeAbbas\\Downloads\\Compressed\\chromedriver_win32\\chromedriver.exe");
String downloadFilepath = desktopPath;
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory",downloadFilepath );
ChromeOptions options = new ChromeOptions();
HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>();
options.setExperimentalOption("prefs", chromePrefs);
options.addArguments("--test-type");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap);
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(cap);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.