How can I set a default profile for the Firefox driver in Selenium Webdriver 3?

前端 未结 2 706
生来不讨喜
生来不讨喜 2020-12-07 03:08

I can\'t set a default profile for Firefox in Selenium Webdriver 3 because there is no such constructor in the FirefoxDriver class.

import org.o         


        
2条回答
  •  情歌与酒
    2020-12-07 03:10

    move your setup to @BeforeClass

    I'm using this setup, works just fine:

    @BeforeClass
    public static void setUpClass() {
        FirefoxOptions options = new FirefoxOptions();
        ProfilesIni allProfiles = new ProfilesIni();         
        FirefoxProfile selenium_profile = allProfiles.getProfile("selenium_profile");
        options.setProfile(selenium_profile);
        options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
        System.setProperty("webdriver.gecko.driver", "C:\\Users\\pburgr\\Desktop\\geckodriver-v0.20.0-win64\\geckodriver.exe");
        driver = new FirefoxDriver(options);
        driver.manage().window().maximize();}
    

    just change paths and profile designation.

提交回复
热议问题