简体   繁体   中英

Python Firefox Selenium Load Profile

I tried many combinations of Geckodrive,Selenium and Python but i could not achieved to load Firefox profile what i need.It loads the default profile. The lastest code is below and I opened an issue on github Selenium page but there is still no solution.There are some solutions about Java but I am not able to bind it in Python.A temp file created on temp folder which includes profile data and cookies.That mean selenium does not use any profile's cookies and other configurations

Any solutions will be apprecited.

Geckodrive version:0.23 Selenium 3.14 Python 3.7 Firefox 61

from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.support.ui import WebDriverWait

fp = FirefoxProfile('C:\\Users\\<USER>\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\ji8rbij6.test')
fp.update_preferences()
browser = webdriver.Firefox(firefox_profile=fp) 

Thanks in advance

PS. I tried this code block in 3 different computer because of being able to have a problem on my own computer

This exact setup works as expected for me (windows10) and I'm able to load custom firefox profiles. Firefox: 88.0.1 Geckodriver: 0.30.0 ( geckodriver releases Python: 3.8.10 robotframework-selenium2library: 3.0.0 robotframework-seleniumlibrary: 6.0.0

import SeleniumLibrary
from selenium import webdriver
from robot.libraries.BuiltIn import BuiltIn
def create_profile(self)
    fp = webdriver.FirefoxProfile()
    fp.set_preference("browser.download.folderList", 2)
    fp.set_preference("browser.download.manager.showWhenStarting", False)
    fp.set_preference("browser.download.panel.shown", False)
    fp.set_preference("browser.download.dir","**provide_download_dir_here**")
    fp.set_preference("browser.helperApps.neverAsk.openFile", 
    "application/zip,application/octet-stream, application/x-zip-compressed, 
    multipart/x-zip,image/jpeg,application/xml,application/pdf,text/plain,text/csv, 
    */*")
    fp.set_preference("browser.helperApps.neverAsk.saveToDisk", 
    "application/zip,application/octet-stream, application/x-zip-compressed, 
    multipart/x-zip,image/jpeg,application/xml,application/pdf,text/plain,text/csv, 
    */*")
    fp.update_preferences()
    return fp.path
# Add the following code where you open the browser
ff = self.create_profile()   
BuiltIn().get_library_instance("SeleniumLibrary").open_browser("https://your_url","F    irefox",ff_profile_dir=ff)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM