How to create profile in Firefox using Selenium WebDriver

前端 未结 5 766
独厮守ぢ
独厮守ぢ 2021-01-05 07:18

When we write something like this:

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

Does it mean we are creatin

5条回答
  •  长情又很酷
    2021-01-05 08:07

    The method call you stated simply creates a java profile object from the given directory of profile information which is then passed to Firefox via the WebDriver instance.

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

    %APPDATA%\Roaming\Mozilla\Firefox

    The Profiles directory within this folder contains the stores of existing Firefox profiles, which are quite handy to copy when you want to use an existing profile as the 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'd then 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 cause Firefox Profile Manager to load the profile and will allow you to then launch Firefox manually with this profile to configure or test it, which is what I presume you want to do.

    Once you have created a named profile in this way, you can assign it to your driver in Selenium like this:

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

    Where "selenium" is the same as the Name property in the profiles.ini file.

提交回复
热议问题