webdrivernanager依赖项是否具有可用于替代默认浏览器下载位置的实现?

我在硒测试中使用WebDriverManager.chromedriver().setup();获取chrome属性。工作正常。我试图通过更改chrome浏览器的默认下载位置来下载文件,因为我想将该文件下载到我的Java项目类路径中,而不是我的本地计算机中,但是我不确定WebDriverManager是否具有这种实现。目前,我正在尝试以下操作:

    WebDriverManager.chromedriver().setup();
    String downloadDir = System.getProperty("user.dir");
    HashMap<String,Object> chromePrefs = new HashMap<String,Object>();
    chromePrefs.put("download.default_directory",downloadDir);
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs",chromePrefs);
    DesiredCapabilities cap = DesiredCapabilities.chrome();
    cap.setCapability(ChromeOptions.CAPABILITY,options);
    driver = new ChromeDriver(cap);

代码块可以正常工作,并将文件下载到项目类路径,正如预期的那样,但是我认为这样做的方法更简洁,更短。我已经对Bonigarcia WebDriverManager依赖性及其一些实现进行了一些研究,但找不到任何有用的方法。有没有更好的方法来实现上述目标?

chenglong876 回答:webdrivernanager依赖项是否具有可用于替代默认浏览器下载位置的实现?

使用方法targetPath()更改WebDriverManager下载的驱动程序的默认位置:

WebDriverManager.chromedriver().targetPath("/my/custom/path").setup();
本文链接:https://www.f2er.com/3117792.html

大家都在问