C#WebDriver Internet Explorer,如何在静默模式下执行?

时间:2013-12-23 18:19:41

标签: c# internet-explorer selenium selenium-webdriver

在C#中使用Internet Explorer Webdriver时,它会在服务器启动时输出此消息:

  

启动InternetExplorerDriver(64位)

     

2.39.0.0

     

收听37227号港口

我发现服务器启动时会有命令行开关 - silent 来抑制诊断输出(https://code.google.com/p/selenium/wiki/InternetExplorerDriver)。

我没有找到如何使用此命令行启动Internet Explorer驱动程序。

我的C#代码

InternetExplorerOptions optionsIE = new InternetExplorerOptions();
optionsIE.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
IWebDriver WebDriver = new InternetExplorerDriver(optionsIE);

我不想看到这些消息,我怎么能压制它们?

感谢您的帮助。

2 个答案:

答案 0 :(得分:3)

这应该接近您想要的代码。 “服务”可执行文件的命令行选项(如IEDriverServer.exe)是通过相应的服务类设置的。

// WARNING: Done from memory without benefit of an IDE.
// May not be entirely accurate, or even compile as written.
InternetExplorerDriverService service = InternetExplorerDriverService.CreateDefaultService();
service.SuppressInitialDiagnosticInformation = true;

InternetExplorerOptions options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;

IWebDriver driver = new InternetExplorerDriver(service, options);

作为旁注和公共服务公告,如果您设置了IntroduceInstabilityByIgnoringProtectedModeSettings选项,You're Doing It Wrong

答案 1 :(得分:0)

试试这个:

optionsIE.ForceCreateProcessApi = true;
optionsIE.BrowserCommandLineArguments = "--silent";
相关问题