无法解析构造函数FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)

有人可以帮我解决这段代码。 目前它会在第4行抱怨:webDriver = new FirefoxDriver(ff_ep_profiles)说它无法解析构造函数。 我需要加载我的扩展,因此我正在创建一个配置文件

FirefoxProfile ff_ep_profile = new FirefoxProfile(new File("C:\\Users\\admin\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\81uy033g.FirefoxEP")); FirefoxOptions option=new FirefoxOptions(); option.setProfile(ff_ep_profile); webDriver = new FirefoxDriver(ff_ep_profile); 

在使用Selenium v​​3.11.xGeckoDriver v0.20.0Firefox Quantum v59.0.2时 ,可以使用不同的选项来调用新的/现有的Firefox配置文件

如果您希望在每次运行Test Execution时使用新的 Firefox Profile ,可以使用以下代码块:

 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"); 

如果您希望在每次运行Test Execution时使用现有的 Firefox Profile ,则必须按照在Windows创建新的Firefox配置文件中的说明手动创建Firefox配置文件

现在,您有两种方法可以调用您创建的Firefox配置文件 ,如下所示:

  • 您可以使用FirefoxOptions类来调用现有的Firefox配置文件 ,您可以使用以下代码块:

     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"); 
  • 您还可以使用DesiredCapabilities类来设置现有的Firefox配置文件 ,然后在FirefoxOptions的实例中进行合并 ,您可以使用以下代码块:

     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");