How to open browser window in incognito/private mode using python selenium webdriver?


We can open a browser window in incognito/private mode with Selenium webdriver in Python using the ChromeOptions class. We have to create an object of the ChromeOptions class.

Then apply the method add_argument to that object and pass the parameter -- incognito has a parameter. Finally, this information has to be passed to the webdriver object.

Syntax

c = webdriver.ChromeOptions()
c.add_argument("--incognito")

Example

from selenium import webdriver
#object of ChromeOptions class
c = webdriver.ChromeOptions()
#incognito parameter passed
c.add_argument("--incognito")
#set chromodriver.exe path
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe",options=c)
driver.implicitly_wait(0.5)
#launch URL
driver.get("https://www.tutorialspoint.com/tutor_connect/index.php")

Output

Updated on: 03-Apr-2021

7K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements