请使用chrome功能查找以下代码.实际上,浏览器没有将文件下载到指定的路径.
private static DesiredCapabilities getChromeCapabilities() throws Exception { String chromePath = BrowserUtil.class.getResource("/Browserdrivers/chromedriver.exe").getPath(); System.setProperty("webdriver.chrome.driver", chromePath); String downloadFilepath = "C:\\TestDownloads"; ChromeOptions options = new ChromeOptions(); HashMapchromePrefs = new HashMap (); chromePrefs.put("profile.default_content_settings.popups", 0); chromePrefs.put("download.default_directory", downloadFilepath); options.setExperimentalOption("prefs", chromePrefs); options.addArguments("--test-type"); options.addArguments("start-maximized", "disable-popup-blocking"); DesiredCapabilities chromeCapabilities = DesiredCapabilities.chrome(); setProxy(chromeCapabilities); chromeCapabilities.setPlatform(Platform.WINDOWS); chromeCapabilities.setCapability("name", MDC.get("testname")); chromeCapabilities.setCapability(ChromeOptions.CAPABILITY, options); return chromeCapabilities; }
Shubham Jain.. 32
对于Chromedriver试用:
String downloadFilepath = "/path/to/download"; HashMapchromePrefs = new HashMap (); chromePrefs.put("profile.default_content_settings.popups", 0); chromePrefs.put("download.default_directory", downloadFilepath); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("prefs", chromePrefs); DesiredCapabilities cap = DesiredCapabilities.chrome(); cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); cap.setCapability(ChromeOptions.CAPABILITY, options); WebDriver driver = new ChromeDriver(cap);
注意: - 在Windows中,你需要使用\\作为路径,如果你使用的是linux或mac,那么使用//
希望这可以帮助.:)
对于Chromedriver试用:
String downloadFilepath = "/path/to/download"; HashMapchromePrefs = new HashMap (); chromePrefs.put("profile.default_content_settings.popups", 0); chromePrefs.put("download.default_directory", downloadFilepath); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("prefs", chromePrefs); DesiredCapabilities cap = DesiredCapabilities.chrome(); cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); cap.setCapability(ChromeOptions.CAPABILITY, options); WebDriver driver = new ChromeDriver(cap);
注意: - 在Windows中,你需要使用\\作为路径,如果你使用的是linux或mac,那么使用//
希望这可以帮助.:)
ans帮助我在Windows上解决这个问题(https://bugs.chromium.org/p/chromedriver/issues/detail?id=783).
Mapprefs = new HashMap (); prefs.put("download.default_directory", System.getProperty("user.dir")+ File.separator + "externalFiles" + File.separator + "downloadFiles"); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("prefs", prefs); ChromeDriver driver = new ChromeDriver(options);