Software Development

How do I launch the Chrome browser in Incognito mode using Selenium WebDriver?

BR Asked by Brenda Foster · 15-12-2025
0 upvotes 12,565 views 0 comments
The question

I am currently automating a suite of tests for a web application where I need to verify that user sessions are not stored between test runs. I’m using the Selenium WebDriver with Python and want to know how to programmatically trigger the Chrome browser to open in Incognito mode. Is there a specific argument or capability I need to pass into the ChromeOptions to achieve this?

3 answers

0
DE
Answered on 17-12-2025

To launch Chrome in Incognito mode, you need to use the ChromeOptions class provided by Selenium. You instantiate the options and then use the add_argument() method to pass the --incognito flag. In Python, your code would look like this: options = webdriver.ChromeOptions() followed by options.add_argument("--incognito"). Finally, you pass these options into your WebDriver initialization. This is a standard practice in automated testing to ensure a clean state, as it prevents the browser from reading or writing cookies and cache from previous sessions, which is crucial for verifying login flows and tracking pixels.

0
JU
Answered on 19-12-2025

Does opening the browser in Incognito mode also disable all your Chrome extensions by default during the Selenium session, or do you have to manually disable those as well to ensure a clean test environment?

MA 20-12-2025

That's a perceptive question, Justin. When Selenium launches Chrome, it typically uses a fresh, temporary profile which already excludes your personal extensions. However, using the --incognito flag further ensures that no local storage or session data is persisted. If you specifically need to test with an extension in Incognito, you actually have to jump through a few more hoops in the manifest settings. For most Software Development testing, simply using the incognito flag is sufficient to isolate the browser environment and mimic a first-time user experience perfectly.

0
SU
Answered on 22-12-2025

You can also achieve this in Java by using options.addArguments("--incognito"); before passing the options object to the ChromeDriver constructor. It works identically across languages.

BR 23-12-2025

I agree with Susan; the flag remains consistent whether you are using Python, Java, or C#. It’s one of the most reliable Chrome switches for Selenium automation enthusiasts.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session