'How to start Edge browser in Incognito mode using selenium remote webdriver?

Currently we are working on selenium (2.53.0) with Edge browser using C#. Edge browser stores cache information at 'localAppdata' folder because of cache, we are facing some issues while test cases execution.

I try to delete all cookies information using selenium (DeleteAllCookies) but it not working for Edge browser.

I read couple of Microsoft forums only way to skip cache, when we start Edge browser on incognito mode.

Can any one suggest how to start Edge browser instance in private (incognito mode) using selenium remote-webdriver



Solution 1:[1]

if you want to open Edge in Private (Incognito) mode, you can use this C# code:

EdgeOptions options = new EdgeOptions();
options.AddAdditionalCapability("InPrivate", true);
this.edgeDriver = new EdgeDriver(options);

Solution 2:[2]

Here is an example of what I use when setting up an EdgeDriver instance. (C#)

private IWebDriver SetupEdgeWebDriver(bool runHeadlessOnPipeline, int implicitWait = 12500)
{
    IWebDriver webDriverInstance;

    EdgeOptions edgeOptions = new EdgeOptions
    {
        //Microsoft Edge (Chromium)
        UseChromium = true
    };

    if (EnableIncognito)
    {
        edgeOptions.AddArgument("inprivate");
    }

    edgeOptions.BinaryLocation = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe";

    //azure devops pipeline
    if (PipelineRun)
    {
        edgeOptions.AddArgument("disable-gpu");
        edgeOptions.AddArgument("window-size=1920,960");

        if (runHeadlessOnPipeline)
        {
            edgeOptions.AddArgument("headless");
        }
    }
    //running on your local machine
    else
    {
        edgeOptions.AddArgument("start-maximized");
    }

    edgeOptions.SetLoggingPreference(LogType.Driver, LogLevel.Debug);

    webDriverInstance = new EdgeDriver(edgeOptions);
    webDriverInstance.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(implicitWait);

    return webDriverInstance;
}

Solution 3:[3]

This is the code I'm using with Selenium.WebDriver 4.0.0 and C# dotnet 5.0

EdgeOptions options = new();
options.AddArguments("InPrivate");
driver = new EdgeDriver(options);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TylerH
Solution 2
Solution 3 Dinh Tran