C# & Selenium WebDriver 4.0+ - Microsoft Edge 配置文件选择窗口阻止测试运行
当尝试使用 Selenium WebDriver 4.10 和 C# (.NET Framework 4.5.2) 使用以下代码构建测试时,我收到一个弹出窗口,要求选择配置文件。据我了解,下面的代码已经指定要使用的配置文件:
string strEdgeProfilePath = @"C:\\Users\\" + Environment.UserName + @"\\AppData\\Local\\Microsoft\\Edge\\User Data";
string strDefautProfilePath = strEdgeProfilePath + @"\\Default";
string strSeleniumProfilePath = strEdgeProfilePath + @"\\Selenium"; // <---- I have deleted this folder and copied the contents of the "Default" folder to no avail.
using (var service = EdgeDriverService.CreateDefaultService(@"C:\Temp\Selenium\Edge")) {
service.UseVerboseLogging = true;
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions.AddArgument("--user-data-dir=" + strSeleniumProfilePath);
edgeOptions.AddArgument("--profile-directory=Selenium");
driver = new EdgeDriver(@"C:\Temp\Selenium\Edge", edgeOptions); // <----- msedgeserve.exe located here
}
即使我选择配置文件,Microsoft Edge 也不会继续并且测试超时。
我可以做什么来阻止配置文件选择并运行测试?
When attempting to build tests using Selenium WebDriver 4.10 and C# (.NET Framework 4.5.2) using the following code I receive a pop-up asking to select a profile. From what I understand the code below already is specifying the profile to use:
string strEdgeProfilePath = @"C:\\Users\\" + Environment.UserName + @"\\AppData\\Local\\Microsoft\\Edge\\User Data";
string strDefautProfilePath = strEdgeProfilePath + @"\\Default";
string strSeleniumProfilePath = strEdgeProfilePath + @"\\Selenium"; // <---- I have deleted this folder and copied the contents of the "Default" folder to no avail.
using (var service = EdgeDriverService.CreateDefaultService(@"C:\Temp\Selenium\Edge")) {
service.UseVerboseLogging = true;
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions.AddArgument("--user-data-dir=" + strSeleniumProfilePath);
edgeOptions.AddArgument("--profile-directory=Selenium");
driver = new EdgeDriver(@"C:\Temp\Selenium\Edge", edgeOptions); // <----- msedgeserve.exe located here
}
Even when I select the profile Microsoft Edge does not continue and the test times out.
What can I do to prevent the profile selection and get the test to run?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码中存在一些问题:
--user-data-dir
的值不正确。使用strEdgeProfilePath
就足够了。因此,正确的代码应该是这样的:
此外,为了避免运行 Edge 进程错误,您需要按照 这个答案。请在代码中使用备份文件夹而不是原始文件夹。
There're some problems in your code:
--user-data-dir
is not right. UsingstrEdgeProfilePath
for it is enough.So the right code should be like this:
Besides, to avoid running Edge processes errors, you need to follow the back up steps in this answer. Please use the backup folder instead of the original folder in the code.