pythonpython-2.7seleniumselenium-webdriver

How to open a private firefox window - selenium


How can I run my selenium web driver in firefox private mode instead of just normal firefox?

I tried the below but it hasn't worked:

firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("browser.privatebrowsing.autostart", True)

driver = webdriver.Firefox(firefox_profile=firefox_profile)

I viewed the question asked before which is mentioned in the comment and above the question but it didn't work.


Solution

  • You could use FirefoxBinary and add_command_line_options:

    from selenium import webdriver
    from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
    
    b = firefox_binary=FirefoxBinary('/usr/bin/firefox')
    b.add_command_line_options("-private")
    dr = webdriver.Firefox(firefox_binary=b)