How to load firefox profile with Python Selenium?

前端 未结 5 994
囚心锁ツ
囚心锁ツ 2021-02-14 20:19

I\'m trying to get Python Selenium to work on my Windows Machine. I\'ve upgraded to the latest versions of Firefox, Selenium, Geckodriver, but I still receive the below error: <

5条回答
  •  猫巷女王i
    2021-02-14 20:53

    You didn't update preferences for profile: profile.update_preferences(). You have to update the profile after set preference. Please following the code below:

    from selenium import webdriver
    from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
    
    profile = webdriver.FirefoxProfile()
    profile.set_preference('browser.download.folderList', 2)
    profile.set_preference('browser.download.manager.showWhenStarting', False)
    profile.set_preference('browser.download.dir', os.getcwd())
    profile.set_preference('browser.helperApps.neverAsk.saveToDisk', ('application/vnd.ms-excel'))
    profile.set_preference('general.warnOnAboutConfig', False)
    profile.update_preferences()
    gecko_path = "path_to_geckodriver\\geckodriver.exe"
    path = "path_to_firefoxs\\Mozilla Firefox\\firefox.exe"
    binary = FirefoxBinary(path)
    driver = webdriver.Firefox(firefox_profile=profile,executable_path=gecko_path)
    

提交回复
热议问题