使用selenium java在firefox gecko驱动程序中自动下载pdf [英] Automatically download pdf in firefox gecko driver using selenium java

查看:603
本文介绍了使用selenium java在firefox gecko驱动程序中自动下载pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助创建配置文件并使用firefox( gecko 驱动程序)设置选项,以自动下载selenium webdriver - java中的文件。我已经搜索了很多谷歌搜索的选项,没有什么工作。所以在堆栈溢出时发布我的查询。如果可能,请帮助一些代码段。这是针对selenium 3和firefox版本52。

Can anyone help to create a profile and set options using firefox (gecko driver) to automatically download files in selenium webdriver - java. I have already searched a lot of options googling around, and nothing much worked. So posting my query on stack overflow. Please help with some code snippet if possible. This is for selenium 3 and firefox version 52.

提前致谢。

推荐答案

1 /在firefox.exe中创建一个新的firefox配置文件-p

1/ create a new firefox profile manualy in firefox.exe -p

2 /使用这个新的配置文件运行firefox并设置为自动下载PDF文件

2/ run firefox with this new profile and set up to automaticly download PDF files

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个导入证书,没有询问,扩展等)。

using existing custom firefox profile, you can run your test with almost any firefox setting modification (proxy setings, 1 imported certificate with no asking, extensions, etc.)

不再需要在代码中指定:

No more need to specify in code:

FirefoxProfile selenium_profile = new FirefoxProfile();
        selenium_profile.setPreference...

这篇关于使用selenium java在firefox gecko驱动程序中自动下载pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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