How to create a profile in Firefox using Selenium WebDriver

When we write something like this:

FirefoxProfile ffprofile = new FirefoxProfile(new File("D:\\Selenium")); 

Does this mean that we are creating a new profile? Because I cannot find any new profile in the Firefox profile section.

So now my question is: how do I create a new profile for the Firefox browser?

+6
source share
5 answers

Calling the method you specified simply creates a java profile object from the specified directory of profile information, which is then passed to Firefox through an instance of WebDriver.

In order for Firefox to save your driver and make it accessible from the profile manager, you need to edit the profiles.ini file on my machine (Windows 7), it was in:

% APPDATA% \ Roaming \ Mozilla \ Firefox

The profiles directory in this folder contains repositories of existing Firefox profiles, which are very convenient for copying when you want to use an existing profile as a template for a new one.

Your mileage may vary depending on your OS, but I'm sure you can find it with a quick search. Using your example, you should add the following to this file (where N in the header is the next unused profile number):

 [ProfileN] Name=selenium IsRelative=0 Path=D:\Selenium 

This will force the Firefox Profile Manager to load the profile and allow you to start Firefox manually with this profile in order to configure or test it, which I suppose you want to do.

Once you create a named profile this way, you can assign it to your Selenium driver as follows:

 ProfilesIni allProfiles = new ProfilesIni(); FirefoxProfile profile = allProfiles.getProfile("selenium"); WebDriver driver = FirefoxDriver(profile); 

Where "selenium" matches the property name in the profiles.ini file.

+6
source

The following code will create a Firefox profile (based on the file provided) and create a new instance of the FF web browser with the loaded profile:

 FirefoxProfile profile = new FirefoxProfile(new File("D:\\Selenium Profile")); WebDriver driver = new FirefoxDriver(profile); 

Perhaps look at the official support page for the FF profile manager or here: Firefox user profile for Selenium to get an idea of ​​FF profiles.

+4
source

You cannot create a profile for firefox using Selenium. What you can do is create a firefox profile for your webdriver from the available profiles in firefox. The words on the Firefox profile sound somewhat ambiguous here.

To create a browser profile in a browser, refer to the Mozilla support page .

+1
source

Here's how I make selenium 3 with geckodriver:

  • Use the firefox command line interface to create a profile

    firefox.exe -CreateProfile "profile_name profile_dir" (In java, run this workspace using the Runtime.getRuntime (). Exec function)

  • Set -profile argument in firefox options

     FirefoxOptions options = new FirefoxOptions(); options.addArguments("-profile", <profile_dir>); driver = new FirefoxDriver(options); 
0
source

Create a profile in Firefox.

Here is the code for using the newly created firefox profile.

 ProfilesIni profile = new ProfilesIni(); FirefoxProfile myprofile = profile.getProfile("firefox profile name"); WebDriver driver = new FirefoxDriver(myprofile); 
-2
source

Source: https://habr.com/ru/post/955562/


All Articles