Selenium – Visual Studios- C# – 所有(chrome,firefox和Internet Explorer)webdrivers无法启动驱动程序服务

我正在尝试设置Selenium进行测试,我的网络驱动程序似乎都没有工作。 我试过在项目文件夹中移动它们,我可以让Visual Studios找到它们的唯一方法是使用@“path”语句。

真正的问题是……一旦Visual Studio找到webdriver,操作就会超时,我得到以下exception:

WebDriver.dll中出现未处理的“OpenQA.Selenium.WebDriverException”类型的exception附加信息:无法在http:// localhost:(每次更改的随机端口号)上启动驱动程序服务

我已经尝试重新启动计算机并让系统管理员检查防火墙和恶意软件阻止程序日志,但似乎都没有帮助(或者他们不知道正确的事情要查找)。

我认为这是一件非常简单的事情,我只是错过了……任何帮助都会非常感激。

这是我的代码的副本:

using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.Support.UI; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using OpenQA.Selenium.Chrome; using OpenQA.Selenium.IE; namespace SeleniumWork { class Program { static void Main(string[] args) { IWebDriver driver = new InternetExplorerDriver(@"C:\blahblahpathstring"); driver.Navigate().GoToUrl("http://www.google.com/"); IWebElement query = driver.FindElement(By.Name("q")); query.SendKeys("Cheese"); query.Submit(); var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); wait.Until(d => d.Title.StartsWith("cheese", StringComparison.OrdinalIgnoreCase)); Console.WriteLine("Page title is: " + driver.Title); } } } 

这是我收到的调试输出的副本:

 A first chance exception of type 'System.Net.WebException' occurred in System.dll A first chance exception of type 'System.Net.WebException' occurred in System.dll A first chance exception of type 'System.Net.WebException' occurred in System.dll A first chance exception of type 'System.Net.WebException' occurred in System.dll A first chance exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll 

我在我的工作机器上遇到了同样的问题,但在我的个人机器上却没有。 我可以在两者之间唯一的区别是我在家里使用VS 2015而在工作中使用VS 2017。

修复它的是我使用NuGet Package Manager进行项目并下载了jbaranda的Selenium.Firefox.WebDriver,后者使用基于marionette的新驱动程序而不是gecko驱动程序。

安装完成后,我可以在没有任何额外配置或选项的情况下启动并运行firefox浏览器:

 IWebDriver driver = new FirefoxDriver(); driver.Url = "www.google.com"; 

而在此之前,它会引发“无法启动驱动程序服务…”的例外情况。 其他浏览器有NuGet包,我建议您使用的是特定的一个,但唯一一个我没有遇到过这个问题的是IE。 希望有所帮助

我遇到了同样的问题,并且根本不知道如何修复它。 最后我发现防火墙阻止了流量回送。 安装在机器上的防火墙是McAffe。

我所做的就是停止管理流量扫描的服务。

希望它会对你有所帮助。

我一直在IEDriverServer上一直这样做,很少在FireFox上。

当它发生在FireFox上时修复了两次 – 第一次更新壁虎驱动程序,第二次重新启动我的PC。 环境中的某些东西正在发生,也许驱动程序有时不会完全退出,所以新的实例化被阻止了?