如何使用Selenium WebDriver在C#中以私有模式启动IE [英] How to start IE in private mode in c# with selenium webdriver

查看:394
本文介绍了如何使用Selenium WebDriver在C#中以私有模式启动IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在C#和Visualstudio中使用Selenium Webdriver.

I'm starting using selenium Webdriver with c# and Visualstudio.

我想以私有模式启动Internetexplorer.因此,在测试期间,我不必在意旧的浏览数据.

I would like to start Internetexplorer in private mode. So I have not to care about old browsing data during my test.

我已经搜索了很长时间,以查找如何执行此操作. 可悲的是我找不到解决方案.

I searched for quite a long time now to find how to do this. Sadly I could not find a solution.

有人可以给我提供一个工作代码段,以显示如何从C#代码以私有模式启动IE吗?

Could anybody provide me with a working code snippet showing how to start IE in private mode from c# code?

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

I used the following command to start the browser normally:

Context.Instance.Driver = new InternetExplorerDriver();

我试图添加它以使其起作用:

I tried to add this to make it work:

InternetExplorerOptions options = new InternetExplorerOptions();
options.BrowserCommandLineArguments = "--private";
Context.Instance.Driver = new InternetExplorerDriver(options);

这绝对是成功的.

最后,我也尝试过此操作:

Finally, I tried this also:

InternetExplorerDriverService service = InternetExplorerDriverService.CreateDefaultService();

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

Context.Instance.Driver = new InternetExplorerDriver(service, options);

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

I would like to have IE running in private mode for my tests.

推荐答案

在这里,

Here, InternetExplorerOptions Members page; it is stated that BrowserCommandLineArguments property only has an effect when the ForceCreateProcessApi is true. ForceCreateProcessApi default value is false.

请尝试手动设置吗?

options.ForceCreateProcessApi = true;
options.BrowserCommandLineArguments = "-private";

这篇关于如何使用Selenium WebDriver在C#中以私有模式启动IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆