无法在FirefoxDriver中加载自定义配置文件:构造函数FirefoxDriver(FirefoxProfile)未定义

时间:2017-10-10 07:25:18

标签: selenium firefox selenium-webdriver geckodriver

我正试图在www.naukri.com上处理多个弹出窗口拦截器;为此,我在firefox命名" AutoProfile"中创建了一个自定义配置文件。但我在firefox驱动程序中加载此自定义配置文件时遇到问题;

driver=new FirefoxDriver(profile3);

但我在The constructor FirefoxDriver(FirefoxProfile) is undefined. 中收到错误说:

   SqlDataAdapter adap = new SqlDataAdapter(cmd2);
   DataSet ds = new DataSet();
   BindingSource bs = new BindingSource();
   bs.DataSource = ds.Tables[0];
   dataGridView1.DataSource = bs;

有些时候我会收到一条消息,因为建造者已被弃用。

2 个答案:

答案 0 :(得分:1)

您使用的Selenium和Geckodriver的版本是什么?

来自https://raw.githubusercontent.com/SeleniumHQ/selenium/master/rb/CHANGES

3.4.1 (2017-06-13)
==================
Firefox:
  * Added new Firefox::Options class that should be used to customize browser
    behavior (command line arguments, profile, preferences, Firefox binary, etc.).
    The instance of options class can be passed to driver initialization using
    :options key. Old way of passing these customization directly to driver
    initialization is deprecated.

要设置个人资料,您应该执行以下操作:

         System.setProperty("webdriver.gecko.driver", "F:\\abc\\geckodriver-v0.18.0-win64\\geckodriver.exe");
        ProfilesIni profile2 = new ProfilesIni();
        FirefoxProfile profile3 = profile2.getProfile("AutoProfile");
        profile3.setPreference("browser.popups.showPopupBlocker", false);

        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setProfile(profile3);

        WebDriver driver = new FirefoxDriver(firefoxOptions);
        driver.get("www.naukri.com"); 

答案 1 :(得分:0)

问题是由于较旧的硒版本共存。 mvn clean install解决了这个问题。

  

更新gecko驱动程序和库

希望你的问题能够得到解决