Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 346
Raghu P Avatar asked Oct 22 '25 05:10

Raghu P


2 Answers

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);
like image 120
mihkov Avatar answered Oct 25 '25 01:10

mihkov


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;
}
like image 29
BernardV Avatar answered Oct 25 '25 01:10

BernardV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!