user2150250
user2150250

Reputation: 5187

How to Make Firefox Driver Same as if Firefox Manually Opened

I've noticed that opening Firefox with a profile using Selenium Webdriver has many differences from opening Firefox manually with the same exact profile. The home page does not load in the Selenium Webdriver driver, non-boolean settings in about:config can't be modified ... to name a couple differences. Is there a way to get Selenium Webdriver to open Firefox drivers to be exactly the same as if you opened Firefox manually?

EDIT: Here is my current code for sanity check purposes ...

        File profileDirectory = new File("C:\\Users\\[UserName]\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\cox74xm7.default");
        FirefoxProfile ffprofile = new FirefoxProfile(profileDirectory);
        WebDriver ffdriver = new FirefoxDriver(ffprofile);

Upvotes: 2

Views: 290

Answers (2)

JimEvans
JimEvans

Reputation: 27496

FirefoxDriver never launches the browser directly using a profile, even if passed in via the constructor using a FirefoxProfile object. A copy of the profile is always made by the driver. The reason for this is that the driver has to account for the use case of a user using the driver to execute multiple instances of Firefox using the same profile. Using the actual profile in situ would make this problematic for obvious reasons. When you pass an existing profile into the driver constructor, it should be copying the entire profile over into the temp directory, and using it as appropriate. Further note, however, that there are some profile settings that must be set with certain settings in order for the driver to function properly.

Upvotes: 1

alecxe
alecxe

Reputation: 474191

You need to instantiate FirefoxProfile and pass it to the WebDriver constructor:

File profileDirectory = new File(path);
FirefoxProfile profile = new FirefoxProfile(profileDirectory);
WebDriver webDriver = new FirefoxDriver(profile);

where path is a path to your existing profile.

Upvotes: 1

Related Questions