【问题标题】:Automatically download pdf in firefox gecko driver using selenium java使用selenium java在firefox gecko驱动程序中自动下载pdf
【发布时间】:2018-05-11 22:30:59
【问题描述】:
任何人都可以帮助创建配置文件并使用 firefox (gecko driver) 自动下载 selenium webdriver - java 中的文件。我已经在谷歌上搜索了很多选项,但没有任何效果。因此,将我的查询发布在堆栈溢出上。如果可能,请帮助一些代码 sn-p。这适用于 selenium 3 和 firefox 52 版。
提前致谢。
【问题讨论】:
-
-
-
参见:How do I do X? SO 的期望是,提出问题的用户不仅会进行研究以回答他们自己的问题,还会分享研究、代码尝试和结果。这表明您已经花时间尝试帮助自己,它使我们免于重复明显的答案,最重要的是它可以帮助您获得更具体和相关的答案!另见:How to Ask
标签:
java
firefox
selenium-webdriver
geckodriver
【解决方案1】:
1/ 在 firefox.exe -p 中手动创建一个新的 firefox 配置文件
2/ 使用这个新配置文件运行 firefox 并设置为自动下载 PDF 文件
3/ 使用这个:
@BeforeClass
public static void setUpClass() {
FirefoxOptions options = new FirefoxOptions();
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile selenium_profile = allProfiles.getProfile("NAME OF THE NEW FIREFOX PROFILE");
options.setProfile(selenium_profile);
options.setBinary("PATH TO FIREFOX.EXE");
System.setProperty("webdriver.gecko.driver", "PATH TO GECKODRIVER.EXE");
driver = new FirefoxDriver(options);
driver.manage().window().maximize();
}
使用现有的自定义 firefox 配置文件,您可以使用几乎任何 firefox 设置修改(代理设置、1 个无需询问的导入证书、扩展等)运行测试
不再需要在代码中指定:
FirefoxProfile selenium_profile = new FirefoxProfile();
selenium_profile.setPreference...