5

To save chromedriver session, I used this snippet of code:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('user-data-dir= path to where to save session')
driver = webdriver.Chrome(executable_path='path to chromedriver.exe', chrome_options=options)

I tried to do the same thing with Firefox but it doesn't seem to work:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.add_argument('user-data-dir= path to where to save session')
driver = webdriver.Firefox(executable_path='path to geckodriver.exe', firefox_options=options)

Is this the right way to go or did I miss something?

Toni Joe
  • 7,715
  • 12
  • 50
  • 69
  • Did you found the solution ? I'm also having same problem and have searched a lot and found no answer, it will be a great help if you share a solution – rahul Jul 23 '20 at 04:22
  • Duplicate of [How to save and load cookies using Python + Selenium WebDriver - Stack Overflow](https://stackoverflow.com/questions/15058462/how-to-save-and-load-cookies-using-python-selenium-webdriver/65535817#65535817) ? – user202729 Oct 27 '21 at 13:55

1 Answers1

1

Below is the manual process to create a new profile and start firefox using existing profile:

  1. To create a new profile, execute command: firefox.exe -CreateProfile JoelUser

  2. To create a new profile in another directory, execute command: firefox.exe -CreateProfile "JoelUser c:\internet\joelusers-moz-profile"

  3. To start firefox using new profile, execute command: firefox.exe -P "Joel User"

Now, to achieve the same programmatically, I figured out that step no. 1 or 2 can be executed using subprocess and step no. 3 can be achieved by following https://stackoverflow.com/a/54065166/6278432

References:

  1. firefox bug - unable to create new session using custom profile: https://github.com/mozilla/geckodriver/issues/1058
    https://bugzilla.mozilla.org/show_bug.cgi?id=1421766

  2. Firefox command line params - https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#user_profile

  3. subprocess api doc - https://docs.python.org/3/library/subprocess.html

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Govinda
  • 582
  • 1
  • 5
  • 14