【问题标题】:How to start Edge browser in Incognito mode using selenium remote webdriver?如何使用 selenium 远程 webdriver 在隐身模式下启动 Edge 浏览器?
【发布时间】:2016-04-11 11:53:01
【问题描述】:

目前我们正在使用 C# 使用 Edge 浏览器开发 selenium (2.53.0)。 Edge浏览器由于缓存的原因将缓存信息存储在'localAppdata'文件夹中,我们在执行测试用例时遇到了一些问题。

我尝试使用 selenium (DeleteAllCookies) 删除所有 cookie 信息,但它不适用于 Edge 浏览器。

当我们在隐身模式下启动 Edge 浏览器时,我阅读了几个微软论坛的唯一方法来跳过缓存。

任何人都可以建议如何使用 selenium remote-webdriver 以私有(隐身模式)启动 Edge 浏览器实例

【问题讨论】:

  • 您是否尝试过检查“退出时删除浏览历史记录”?

标签: microsoft-edge incognito-mode


【解决方案1】:

如果你想在私有(隐身)模式下打开 Edge,你可以使用这个 C# 代码:

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

【讨论】:

  • 这是什么语言?如何实现这一点?
  • 这是一个 C# 示例。当您在开始与浏览器交互之前初始化驱动程序时,将使用截断的代码。签出示例项目here
  • 如何将 Uri 设置为远程 Web 驱动程序?
  • 我不确定我是否“设置”了驱动程序的 Uri。我是这样使用的:Driver.Navigate().GoToUrl(@"http://localhost:5005");驱动初始化后,你可以查看完整的例子here
【解决方案2】:

这是我在设置EdgeDriver 实例时使用的示例。 (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;
}

【讨论】:

    【解决方案3】:

    这是我在 Selenium.WebDriver 4.0.0 和 C# dotnet 5.0 中使用的代码

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多