IE在私有模式下使用Selenium C#
问题描述:
我想在专用模式下打开IE来运行测试用例集.浏览器未打开.错误显示为
I want to open IE in Private mode to run the set of test cases. The browser is not opening. It shows error as
The HTTP request to the remote WebDriver server for URL {URL} timed out after 60 seconds
示例代码:
InternetExplorerOptions options = new InternetExplorerOptions()
{
ForceCreateProcessApi = true,
BrowserCommandLineArguments = "-private",
};
IWebDriver driver = new InternetExplorerDriver("C:\\Reports", options);
driver.Navigate().GoToUrl("https://www.google.com");
我还在注册表编辑器中将TabProcGrowth更改为0.
Also I have changed the TabProcGrowth as 0 in Registry Editor.
如何在私有模式下打开IE来运行测试用例?我想在代码中进行任何更新.预先感谢.
How to open IE in private mode to run the test case? Anything I want to update in my code. Thanks in advance.
答
这是我设法启动它的方式:
This is how I manage to launch it:
- 在注册表编辑器中将TabProcGrowth设置为0.
- 获取Selenium.WebDriver.IEDriver64块(而不是普通的32个块)并构建项目
- 从bin \ Debug \ netcoreapp3.1(生成此文件的输出文件夹取决于您的TargetFramework:.netcore或.netstandard)获取IEDriverServer64.exe.
- 将该文件重命名为IEDriverServer.exe,并将其放在文件夹中的某个位置
- 使用该文件夹的路径创建驱动程序实例.就我而言,我在项目中创建了一个文件夹,并指向该文件夹
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using System.IO;
namespace InternetExplorerPrivate
{
public class Tests
{
public IWebDriver driver;
[SetUp]
public void Setup()
{
InternetExplorerOptions options = new InternetExplorerOptions();
options.ForceCreateProcessApi = true;
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
options.BrowserCommandLineArguments = "-private";
driver = new InternetExplorerDriver(Path.GetFullPath(@"..\..\..\IEDriver"), options);
}
[Test]
public void Test1()
{
driver.Navigate().GoToUrl("https://stackoverflow.com/");
}
}
}