如何使用Selenium WebDriver下载Chrome中的pdf文件 [英] How to download a pdf file in chrome using selenium webdriver

查看:1256
本文介绍了如何使用Selenium WebDriver下载Chrome中的pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用硒下载Chrome中的pdf.

I want to download pdf in chrome using selenium.

System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")  
               + System.getProperty("file.separator")
               + "BrowserDrivers"
               + System.getProperty("file.separator")
               + "chromedriver.exe");

String downloadFilepath = "C:\\Users\\Vinod\\Downloads";

HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);

//Save Chrome Opions
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);


driver = new ChromeDriver(cap);
driver.get(url);

我尝试了上面的代码,但是没有用

I tried above code but its not working

推荐答案

您可以加载此页面并使用硒导航更改设置:

You might load this page and change the setting using selenium navigations:

chrome://settings/content/pdfDocuments

这篇关于如何使用Selenium WebDriver下载Chrome中的pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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