4

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

Web_Designer
  • 72,308
  • 93
  • 206
  • 262
Raghu P
  • 51
  • 1
  • 1
  • 3

3 Answers3

3

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);
TylerH
  • 20,799
  • 66
  • 75
  • 101
mihkov
  • 1,171
  • 13
  • 37
  • What language is this? How would one implement this? – TylerH Dec 27 '18 at 20:44
  • This is a C# Example. The code snipped is used when you initialize the driver just before start interacting with the browser. Checkout a the sample project [here](https://github.com/M-Yankov/SeleniumNetCore/blob/master/src/SampleWebForQA.UI.Tests/EdgeTests.cs) – mihkov Dec 28 '18 at 07:19
  • How do you set the Uri to the remote web dirver? – cocacho Aug 07 '20 at 15:00
  • I am not sure that I "set" the Uri of the driver. I used it like: `Driver.Navigate().GoToUrl(@"http://localhost:5005");` after the the driver is initialized, you can check the full example [here](https://github.com/M-Yankov/SeleniumNetCore/blob/master/src/SampleWebForQA.UI.Tests/FunctionTests.cs) – mihkov Aug 11 '20 at 10:38
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;
}
BernardV
  • 640
  • 10
  • 28
0

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);
Dinh Tran
  • 535
  • 4
  • 13