I have the following script:
#!/usr/bin/python3
from selenium import webdriver
import time
def getProfile():
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.privatebrowsing.autostart", True)
return profile
def main():
browser = webdriver.Firefox(firefox_profile=getProfile())
#browser shall call the URL
browser.get("http://www.google.com")
time.sleep(5)
browser.quit()
if __name__ == "__main__":
main()
How can I manage Firefox to start in private mode?
Referring to the @Laas's point at How might I simulate a private browsing experience in Watir? (Selenium):
Selenium is equivalent to turning on Private Browsing.
And the definition of "Private Browsing":
Private Browsing allows you to browse the Internet without saving any information about which sites and pages you’ve visited.
And since every time you start firefox through selenium webdriver it creates a brand new anonymous profile, you are actually browsing privately.
If you still want to force the private mode in Firefox, set the browser.privatebrowsing.autostart
configuration option to true
:
from selenium import webdriver
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("browser.privatebrowsing.autostart", True)
driver = webdriver.Firefox(firefox_profile=firefox_profile)
Also, see:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With