我在 Win10 (17134.471) 机器上使用 VS2017,我刚刚安装了 Selenium。我可以让 Chrome、Firefox、Edge 工作,但不能让 IE11 (11.471.171340) 工作。我相信我已经完成了所有其他建议的更新,但继续得到:
There are no more files.
目前还不清楚我使用 NuGet 安装需要安装什么,版本是:
- Selenium.WebDriver v3.141.0(自 3.6.0.0 起 14 次更新)
- Selenium.WebDriver64 v3.11.0.1
Selenium.Webdriver.MicrosoftDriver v17.17134.0
测试名称:IeMethod 测试全名:utLearn2018.FirstTestClass.IeMethod 测试源:C:\Users\stephan\Documents\Visual Studio 2017\Projects\utLearn2018\utLearn2018\FirstTestClass.cs:第 44 行测试结果:失败测试持续时间:0:00 :22.3336919
结果堆栈跟踪:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.IE.InternetExplorerDriver..ctor(InternetExplorerDriverService service, InternetExplorerOptions options)
at OpenQA.Selenium.IE.InternetExplorerDriver..ctor()
at utLearn2018.FirstTestClass.IeMethod() in C:\Users\stephan\Documents\Visual Studio 2017\Projects\utLearn2018\utLearn2018\FirstTestClass.cs:line 53
结果消息:
Test method utLearn2018.FirstTestClass.IeMethod threw exception:
System.InvalidOperationException: Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070012 ('There are no more files.') for URL 'http://localhost:50326/' (SessionNotCreated)
我的代码如下:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.IE;
[TestMethod]
public void IeMethod()
{
InternetExplorerOptions options = new InternetExplorerOptions
{
IntroduceInstabilityByIgnoringProtectedModeSettings = true,
EnableNativeEvents = false,
EnsureCleanSession = true
};
IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl("http://www.google.com");
driver.Manage().Window.Maximize();
driver.Close();
driver.Quit();
}