Automatically download pdf in firefox gecko driver using selenium java

ⅰ亾dé卋堺 提交于 2019-11-28 13:58:23

问题


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.

Thanks in advance.


回答1:


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

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

3/ use this:

@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();

    }

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...


来源:https://stackoverflow.com/questions/50276253/automatically-download-pdf-in-firefox-gecko-driver-using-selenium-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!