【问题标题】:Unable to load custom profile in FirefoxDriver : The constructor FirefoxDriver(FirefoxProfile) is undefined无法在 FirefoxDriver 中加载自定义配置文件:构造函数 FirefoxDriver(FirefoxProfile) 未定义
【发布时间】:2017-10-10 07:25:17
【问题描述】:

我正在尝试处理 www.naukri.com 中的多个弹出窗口阻止程序;为此,我在 Firefox 中创建了一个自定义配置文件,命名为“AutoProfile”。但我在 Firefox 驱动程序中加载此自定义配置文件时遇到问题;

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);
driver =new FirefoxDriver(profile3);
driver.get("www.naukri.com");

但我在driver=new FirefoxDriver(profile3); 中收到错误消息:

The constructor FirefoxDriver(FirefoxProfile) is undefined. 

有时我会收到一条消息,因为构造函数已被弃用。

【问题讨论】:

    标签: selenium firefox selenium-webdriver geckodriver


    【解决方案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"); 
    

    【讨论】:

    • 感谢您的回复。它确实解决了我的问题。再次感谢您!
    • @JohnDoe 很高兴为您提供帮助,欢迎来到 Stack Overflow。如果此答案或任何其他答案解决了您的问题,请将其标记为已接受:stackoverflow.com/help/someone-answers
    【解决方案2】:

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

    更新壁虎驱动和库

    希望你的问题能得到解决

    【讨论】:

    • 感谢您的回复,我确实下载了最新的库和壁虎驱动程序。但问题仍然存在..
    猜你喜欢
    • 1970-01-01
    • 2021-05-06
    • 1970-01-01
    • 2018-09-15
    • 1970-01-01
    • 2014-06-24
    • 2021-08-24
    • 1970-01-01
    相关资源
    最近更新 更多