如何使用selenium webdriver在c#中以私有模式启动IE

DRK*_*DRK 2 c# internet-explorer selenium-webdriver

我开始使用selenium Webdriver与c#和Visualstudio.

我想以私人模式启动Internetexplorer.所以我在测试期间不必关心旧的浏览数据.

我现在搜索了很长时间才发现如何做到这一点.可悲的是,我找不到解决方案.

任何人都可以向我提供一个工作代码片段,展示如何从c#代码以私有模式启动IE?

我使用以下命令正常启动浏览器:

Context.Instance.Driver = new InternetExplorerDriver();
Run Code Online (Sandbox Code Playgroud)

我试图添加它以使其工作:

InternetExplorerOptions options = new InternetExplorerOptions();
options.BrowserCommandLineArguments = "--private";
Context.Instance.Driver = new InternetExplorerDriver(options);
Run Code Online (Sandbox Code Playgroud)

这是成功的.

最后,我也尝试了这个:

InternetExplorerDriverService service = InternetExplorerDriverService.CreateDefaultService();

service.SuppressInitialDiagnosticInformation = true;
InternetExplorerOptions options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
options.BrowserCommandLineArguments = "-private";

Context.Instance.Driver = new InternetExplorerDriver(service, options);
Run Code Online (Sandbox Code Playgroud)

我想让IE在私有模式下运行我的测试.

taf*_*afa 6

在这里,InternetExplorerOptions会员页面; 据说BrowserCommandLineArguments财产只有在ForceCreateProcessApi真实时才有效.ForceCreateProcessApi的默认值为false.

你能尝试手动设置吗?

options.ForceCreateProcessApi = true;
options.BrowserCommandLineArguments = "-private";
Run Code Online (Sandbox Code Playgroud)