Cannot resolve constructor FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)

前端 未结 1 415
眼角桃花
眼角桃花 2020-11-27 08:29

Can someone help me with this piece of code. Currently it will complain on line #4 : webDriver = new FirefoxDriver(ff_ep_profiles) saying it cannot resolve constructor. I ne

相关标签:
1条回答
  • 2020-11-27 09:10

    While working with Selenium v3.11.x, GeckoDriver v0.20.0 and Firefox Quantum v59.0.2 there are different option to invoke a new/existing Firefox Profile

    If you are looking to use a new Firefox Profile on every run of your Test Execution you can use the following code block :

    System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
    FirefoxOptions options = new FirefoxOptions();
    options.setProfile(new FirefoxProfile());
    WebDriver driver = new FirefoxDriver(options);
    driver.get("https://www.google.com");
    

    If you are looking to use an existing Firefox Profile on every run of your Test Execution first you have to create a Firefox Profile manually following the instructions at Creating a new Firefox profile on Windows.

    Now you have 2 ways to invoke the Firefox Profile you have created as follows :

    • You can use the FirefoxOptions class to invoke the existing Firefox Profile and you can use the following code block :

      System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
      ProfilesIni profile = new ProfilesIni();
      FirefoxProfile testprofile = profile.getProfile("debanjan");
      FirefoxOptions opt = new FirefoxOptions();
      opt.setProfile(testprofile);
      WebDriver driver =  new FirefoxDriver(opt);
      driver.get("https://www.google.com");
      
    • You can also use the DesiredCapabilities class to set the existing Firefox Profile and later merge within an instance of FirefoxOptions and you can use the following code block :

      System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
      ProfilesIni profile = new ProfilesIni();
      FirefoxProfile testprofile = profile.getProfile("debanjan");
      DesiredCapabilities dc = DesiredCapabilities.firefox();
      dc.setCapability(FirefoxDriver.PROFILE, testprofile);
      FirefoxOptions opt = new FirefoxOptions();
      opt.merge(dc);
      WebDriver driver =  new FirefoxDriver(opt);
      driver.get("https://www.google.com");
      
    0 讨论(0)
提交回复
热议问题