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

标签 c# internet-explorer selenium-webdriver

我开始将 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/

相关文章:

python - 无法通过 Selenium 进行正确的屏幕截图

javascript - 如何知道是否在另一个页面上单击了按钮?

c# - 如何在 C# 中创建键/值对数组?

html - 我在 Internet Explorer 下测试我的元素时出现网页设计错误

javascript - IE8 event.currentTarget 为 null 或不是对象

python - 语法错误: invalid syntax while using find_element_by_xpath using Selenium in Python

python-3.x - '[Errno 26] 文本文件忙 : '/home/*****/.wdm/drivers/chromedriver/83.0.4103.39/linux64/chromedriver' '

c# - Gtk# 使 EventBox 透明的示例

javascript - C# 与 Moment.js 中的日期差异计算

internet-explorer - 在IE中访问音频文件