Python / Selenium / Firefox: Can't start firefox with specified profile path

后端 未结 2 1699
清歌不尽
清歌不尽 2020-11-30 14:23

I try to start firefox with specified profile:

firefox_profile = webdriver.FirefoxProfile(\'/Users/p2mbot/projects/test/firefox_profile\')
driver = webdriver         


        
2条回答
  •  眼角桃花
    2020-11-30 15:28

    Thanks to @m3nda i found a simmilar and terrible solution for windows und python 3. As Jake Hilborn noticed it's not working anymore. The problem is, that driver.firefox_profile.path seems to be the tmp profile direktory, but this is a blanc version. no changes will be safed here. if you open in Firefox about:support there ist the real Path of the Profile.

    from selenium import webdriver
    from selenium.webdriver.firefox.options import Options
    import os
    
    #Start Browser
    option = Options()
    #set options as u like, for example:
    option.log.level = "warn"
    option.set_preference("browser.link.open_newwindow", 3)
    option.set_preference("browser.link.open_newwindow.restriction", 0)
    #load profile
    cwd = os.getcwd()
    pfadffprofile = cwd+"\\"+"ffprofile.selenium"
    ffprofile = webdriver.firefox.firefox_profile.FirefoxProfile(profile_directory = pfadffprofile)
    driver = webdriver.Firefox(firefox_profile= ffprofile, options=option)
    print("Get FF Temp Profile Path")
    driver.get("about:support")
    box = driver.find_element_by_id("profile-dir-box")
    ffTempProfilePath = box.text
    print("ffTempProfilePath: ",ffTempProfilePath)
    
    # now do ur stuff
    
    #copy ur stuff after use or periodically
    print("safe Profile")
    cwd = os.getcwd()
    pfadffprofile = cwd+"\\"+"ffprofile.selenium"
    print ("saving profile " + ffTempProfilePath + " to " + pfadffprofile)
    os.system("xcopy " + ffTempProfilePath + " " + pfadffprofile +" /Y /G /K /R /E /S /C /H")
    print ("files should be copied :/") 
    
    #close driver
    driver.quit()
    

提交回复
热议问题