how to create a new (persistent) firefox profile with selenium in python?

  • Last Update :
  • Techknowledgy :

Many sites, however, offer a remember-me or a stay-logged-in option on their login page which, if used, will store a persistent cookie by which the session can be restored. I used the following script to test this out with gmail,

from selenium import webdriver
url = "https://mail.google.com"
fp = webdriver.FirefoxProfile('/Users/<username>/Library/Application Support/Firefox/Profiles/71v1uczn.default')
   driver = webdriver.Firefox(fp)
   driver.get(url)

Suggestion : 2

Add the extension (directory, .zip or .xpi) at the given path to the profile., #add_extension(path, name = extension_name_for(path)) ⇒ Object Add the extension (directory, .zip or .xpi) at the given path to the profile. ,Set a preference for this particular profile., #[]=(key, value) ⇒ Object Set a preference for this particular profile.

[TrueClass, FalseClass, Integer, Float, String].freeze
{
   "browser.newtabpage.enabled" => false,
   "browser.startup.homepage" => "about:blank",
   "browser.usedOnWindows10.introURL" => "about:blank",
   "network.captive-portal-service.enabled" => false,
   "security.csp.enable" => false
}.freeze

profile = Selenium::WebDriver::Firefox::Profile.new
profile['network.proxy.http'] = 'localhost'
profile['network.proxy.http_port'] = 9090

driver = Selenium::WebDriver.for: firefox,: profile => profile
68
69
70
71
72
73
# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 68

def initialize(model = nil)
@model = verify_model(model)

@additional_prefs = read_model_prefs
@extensions = {}
end
37
38
39

Suggestion : 3

Aadd the extension (directory, .zip or .xpi) at the given path to the profile., #add_extension(path) ⇒ Object Aadd the extension (directory, .zip or .xpi) at the given path to the profile. ,Set a preference for this particular profile., #initialize(directory = nil) ⇒ Profile constructor Create a new Profile instance.

"WEBDRIVER_ANONYMOUS_PROFILE"
"[email protected]"
"http://www.mozilla.org/2004/em-rdf#"
File.expand_path("#{WebDriver.root}/selenium/webdriver/firefox/extension/webdriver.xpi")

profile = Selenium::WebDriver::Firefox::Profile.new
profile['network.proxy.http'] = 'localhost'
profile['network.proxy.http_port'] = 9090

driver = Selenium::WebDriver.for: firefox,: profile => profile
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54