Answer the question
In order to leave comments, you need to log in
How to save installed firefox addon via selenium?
Hello everyone, there is a part of such code
count = 1
profile = "/home/user/.mozilla/firefox/profile" + str(count)
fp = webdriver.FirefoxProfile(profile)
directory = '/home/user/ffadns/'
files = os.listdir(directory)
def randaddon():
addon = directory + random.choice(files)
return addon
fp.add_extension(randaddon())
fp.add_extension(randaddon())
fp.add_extension(randaddon())
driver = webdriver.Firefox(fp)
Answer the question
In order to leave comments, you need to log in
When installing the addon (the addon works without restarting), changes occur in the files that are on the
PS screen. As a result, it turns out that selenium creates a copy of the profile folder in the temporary directory and works with it. After closing via driver.quit(), this folder is deleted, respectively, everything that is installed and recorded (addons, settings, etc.) disappear with this folder. As a solution, I have made this code for myself (for the pros, of course, the code will seem like a ridiculous perversion, but what can you do, everyone once started =) )
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
import datetime
import time
import random
from datetime import datetime
from random import randint
from random import choice
from string import ascii_lowercase
from string import digits
import os
import shutil
from shutil import copytree, ignore_patterns
def regger():
count = 1
login = '[email protected]'
shutil.copytree('/home/user/.mozilla/firefox/source/', "/home/user/.mozilla/firefox/"+ str("source") + str(count))
profile = "/home/user/.mozilla/firefox/source" + str(count)
fp = webdriver.FirefoxProfile(profile)
# Addons
directory = '/home/user/ffadns/'
files = os.listdir(directory)
addon = directory + str(random.choice(files)); addon2 = directory + str(random.choice(files)); addon3 = directory + str(random.choice(files))
fp.add_extension(addon); fp.add_extension(addon2); fp.add_extension(addon3)
addon_name = addon.split('/'[-1]) ; addon2_name = addon2.split('/'[-1]); addon3_name = addon3.split('/'[-1])
driver = webdriver.Firefox(fp)
dd = fp.profile_dir.split('/')
tempProfile_name = dd[-2]
shutil.move('/tmp/' + str(tempProfile_name) + '/webdriver-py-profilecopy/', '/tmp/' + str(login))
shutil.copytree('/tmp/' + login, '/home/user/.mozilla/firefox/' + login, ignore=ignore_patterns('lock'))
shutil.rmtree('/home/user/.mozilla/firefox/source1')
driver.quit()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question