HTMLUnit设置下载位置 [英] HtmlUnit set download location

查看:67
本文介绍了HTMLUnit设置下载位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我正在使用HtmlUnit执行Selenium脚本.在测试脚本执行时,如何为下载的zip文件设置下载位置.

Currently I am executing selenium script with HtmlUnit. How can I set the Download location for the zip file downloaded at the time of test script execution.

推荐答案

您可以在无头模式下使用chrome驱动程序.您只需将选项添加为无头模式,如下所示:-

You can use chrome driver in headless mode.you just need to add options as headless as below :-

   chromeOptions.addArguments("--headless");

完整的Java代码如下所示:-

The full code in Java will appear as below:-

 System.setProperty("webdriver.chrome.driver","D:\\Workspace\\JmeterWebdriverProject\\src\\lib\\chromedriver.exe");
 ChromeOptions chromeOptions = new ChromeOptions();
 chromeOptions.addArguments("--headless");
 chromeOptions.addArguments("--start-maximized");
 WebDriver driver = new ChromeDriver(chromeOptions);
 driver.get("https://google.com");

您可以使用chromedriver通过以下代码在特定路径中设置下载:-

You can use chromedriver to set download in a specific path by below code :-

String downloadFilepath = "/path/to/download";
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();
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);

希望它会为您提供帮助:)

Hope it will help you :)

这篇关于HTMLUnit设置下载位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆