我开始将 selenium Webdriver 与 c# 和 Visualstudio 结合使用。
我想以私有(private)模式启动 Internetexplorer。所以我在测试期间不必关心旧的浏览数据。
我搜索了很长时间才找到如何做到这一点。 可悲的是我找不到解决方案。
任何人都可以向我提供一个工作代码片段,展示如何从 C# 代码以私有(private)模式启动 IE 吗?
我使用如下命令正常启动浏览器:
Context.Instance.Driver = new InternetExplorerDriver();
我试图添加这个以使其工作:
InternetExplorerOptions options = new InternetExplorerOptions();
options.BrowserCommandLineArguments = "--private";
Context.Instance.Driver = new InternetExplorerDriver(options);
这并不成功。
最后,我也试了一下:
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 在我的测试中以私有(private)模式运行。
最佳答案
在这里,InternetExplorerOptions Members页;据说明,BrowserCommandLineArguments
属性仅在 ForceCreateProcessApi
为真时才有效。 ForceCreateProcessApi 默认值为 false。
请您尝试手动设置它好吗?
options.ForceCreateProcessApi = true;
options.BrowserCommandLineArguments = "-private";
关于c# - 如何使用selenium webdriver在c#中以私有(private)模式启动IE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31423773/