使用Selenium C#以私有模式打开IE

Open IE in private mode using Selenium C#

我想以私有模式打开 IE 浏览器以 运行 使用 Selenium webdriver c# 的自动化测试用例集。

我已使用以下选项以隐私模式打开浏览器。

BrowserCommandLineArguments = "private",
ForceCreateProcessApi = true,

但是显示如下错误

Unexpected error launching Internet Explorer. Unable to use CreateProcess() API. To use CreateProcess() with Internet Explorer 8 or higher, the value of registry setting in HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\TabProcGrowth must be '0'..

谁能告诉我怎么解决?

我尝试使用 IE 11 浏览器在 Win 10 上测试代码,发现代码运行正常。

            InternetExplorerOptions options = new InternetExplorerOptions()
            {
                ForceCreateProcessApi = true,
                BrowserCommandLineArguments = "-private",
            };
            IWebDriver driver = new InternetExplorerDriver(@"IE_driver_path_here...",options);
           
            driver.Navigate().GoToUrl("https://Your_URL_here...");

在 IE 11 中的输出:

从错误消息来看,注册表中 TabProcGrowth 项的值似乎不是 0,这导致了此错误。

请参考以下步骤。

  1. 启动注册表编辑器。
  2. 浏览到下面的路径。

Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main

  1. 找到 TabProcGrowth 键并双击它。
  2. 将其值设置为 0,然后单击“确定”按钮。

然后,再次尝试 运行 代码。