stop selenium from creating new firefox profile every launch

404 Views Asked by At

I am using selenium and yaml from a code got from a friend that creates a new Firefox profile every launch and I want to use my own profile, not a new profile

This is part of the code and i have been searching and trying everything to fix the problem but I couldn't figure out what to do more:

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

with open("assets/config.yaml", "r") as config:
    config = yaml.safe_load(config)

options = Options()
if config.get("settings").get("headless"):
    options.headless = True

    profile = webdriver.Firefox(executable_path=config.get("settings").get("firefox"), service_log_path=os.path.devnull if not config.get("settings").get("log") else config.get("settings").get("log"), options=options)

And this is the code from config.yaml:

settings:
  headless: False
  firefox: assets/geckodriver.exe
  log: null
1

There are 1 best solutions below

2
On

I've used it with Java, so in general maybe you can follow this steps:

  1. Create a profile with Firefox.exe -p which creates it in the "C:\Users\xUser\AppData\Roaming\Mozilla\Firefox\Profiles" as xyz.Selenium.
  2. There should be a FirefoxProfile class in the Python binding.
  3. Pass that file to that class and use the profile object in the driver object.