Raghu P
Raghu P

Reputation: 65

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

Upvotes: 4

Views: 14362

Answers (3)

Dinh Tran
Dinh Tran

Reputation: 614

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);

Upvotes: 2

BernardV
BernardV

Reputation: 766

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;
}

Upvotes: 3

mihkov
mihkov

Reputation: 1189

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);

Upvotes: 3

Related Questions