当我们尝试使用配置文件启动Firefox浏览器时无法启动

时间:2019-03-29 13:02:23

标签: selenium firefox add profile

We'd like to  launch the Firefox browser with profile initialization . but it is not opening and failing with below error message.

org.openqa.selenium.firefox.Preferences.readDefaultPreferences(Preferences.java:95)上的“ java.lang.NoClassDefFoundError:org / openqa / selenium / remote / JsonToBeanConverter”

 **My current software version details** 
Selenium 3.14
Firefox browser 66
Gecko driver version V 0.24


System.setProperty("webdriver.gecko.driver", "C:\\geckodriver.exe");
ProfilesIni prof = new ProfilesIni();
FirefoxProfile profile = prof.getProfile("Auto");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
return new FirefoxDriver(capabilities);


I tried to launch the Firefox browser with above configuration 
 As per the above code we have created a profile manually and trying to launch the browser with created profile . We have added add block plus plugin in the profile. because Random popup is appearing in our application . so we want to block it by adding the random popup filename is the add block plus filter.

**Actual Result :**Browser is not launching 
**Expected Result :**Browser should launch

2 个答案:

答案 0 :(得分:0)

确保已创建Auto个人资料。有关如何管理配置文件,请参见https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles

关闭所有firefox实例并打开firefox管理器。您应该在列表中看到配置文件。 enter image description here

下面是工作代码。

ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("Auto");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, myprofile);
WebDriver driver =  new FirefoxDriver(capabilities);
driver.get("https://google.com");
driver.quit();

答案 1 :(得分:0)

您的pom.xml显示您正在使用Selenium版本3.14.0,该版本不支持geckodriver 0.24;尝试更新到硒版本3.141.59,您应该只需要以下硒依赖项:

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-remote-driver</artifactId>
            <version>3.141.59</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
            <scope>test</scope>
        </dependency>