http://localhost:8080问题建议如何更改将在以后由selenium使用的firefox配置文件中的默认下载目录。在我的情况下,我必须默认将.pdf文件下载到某个目录。问题是,在Web驱动程序的每个实例中使用新的配置文件会提示下载对话框(默认情况下不会下载)。
使用默认配置文件会将当前会话与现有会话混淆(如果存在)。
ProfilesIni profile = new ProfilesIni();
// The default profile that is used "outside" of selenium
FirefoxProfile firefoxProfile = profile.getProfile("default");
WebDriver webDriver = new FirefoxDriver(firefoxProfile);
在默认配置文件中,根据需要下载pdf文件,而不提示下载对话框。
如何自定义网络驱动程序使用的配置文件,以便在selenium中下载pdf文件(无需代表用户进行确认)?
答案 0 :(得分:0)
浏览器设置可以在Web驱动程序中设置为首选项,如下所示:
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv, application/csv, text/comma-separated-values");
WebDriver webDriver = new FirefoxDriver(firefoxProfile);
只需将文件的MIME类型添加到上面的首选项列表中即可。