0

I am trying to test Selenium in incognito mode. I've looked up online about how to make it in Python but couldn't really find a new version of the procedure. From what I could find, I made following script:

from selenium.webdriver import Chrome
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  
options = Options()
options.add_argument("−−incognito")
c = DesiredCapabilities.CHROME.copy()

s = Service('C:\Program Files (x86)\chromedriver.exe')
driver = Chrome(service=s, options=options, desired_capabilities=c)

But this doesn't make the browser to launch in incognito mode. What is wrong here? What could I add to make it work?

  • Does this answer your question? [Python/Selenium incognito/private mode](https://stackoverflow.com/questions/27630190/python-selenium-incognito-private-mode) – Maximilian Burszley Mar 25 '22 at 13:09

1 Answers1

0

You don't need to pass the DesiredCapabilities object unless you are using the Remote WebDriver.


Solution

As you are using Chrome() effectively your code block will be:

from selenium.webdriver import Chrome
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("−−incognito")
s = Service('C:\Program Files (x86)\chromedriver.exe')
driver = Chrome(service=s, options=options)
undetected Selenium
  • 151,581
  • 34
  • 225
  • 281
  • I tried this one, and had it close to similar before as well. Sadly it doesn't make the driver start in incognito mode for me. – Donnerhorn Mar 25 '22 at 14:00
  • Just a question. Why incognito? As much as I used selenium(though I didn't use much) it opens a complete different window which has no history/cookies/accounts and neither it does save them anywhere. It's kinda like incognito itself so why to open it in incognito window? – I-am-developer-9 Mar 25 '22 at 15:54