Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a new (persistent) Firefox profile with Selenium in Python?

Trynig to add a new, persistent, Firefox profile with Selenium. AFAIK, when executing FirefoxProfile(), a new profile is generated using a temporary file. Ideally, this profile should be able to remain available to subsequent processes - even after the creator is closed.

Problem:

  1. Create a new Firefox profile from within Python code. This should return a FirefoxProfile object that is usable with the Firefox webdriver Selenium uses.
  2. The profile created should persist after the process ends - i.e. it should be a full-fledged profile, not just a temporary profile.

Some pointers:

  1. The profiles.ini file seems to be key. I have read some code that uses the Java class ProfilesIni to modify profile information. If this class is available for Python code, it should probably take care of most of this.

  2. If the only way to do this is to manually modify the profiles.ini file, that's acceptable. A better, more standardized solution (one that uses a library or Selenium code) would be preferable, however.

Thanks very much!

like image 794
Juan Carlos Coto Avatar asked May 07 '13 15:05

Juan Carlos Coto


1 Answers

If this helps anyone, what needs to be done is run:

firefox[.exe] -CreateProfile <profile_name>

The .exe in brackets is intended to provide for it being run under Windows.

Yes, this does not use the Selenium library in Python, but it does provide the desired result.

like image 80
Juan Carlos Coto Avatar answered Nov 07 '22 05:11

Juan Carlos Coto