简体   繁体   English

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

[英]Selenium - Visual Studios- C# - All (chrome, firefox, and internet explorer) webdrivers unable to start driver service

I'm trying to set up Selenium for testing and none of my webdrivers seem to work.我正在尝试设置 Selenium 进行测试,但我的网络驱动程序似乎都没有工作。 I have tried moving them around in the project folder and the only way I can get Visual Studios to locate them is with a @"path" statement.我曾尝试在项目文件夹中移动它们,而让 Visual Studios 找到它们的唯一方法是使用 @"path" 语句。

The real problem is... Once Visual Studio locates the webdriver, the operation times out and I get the following exception:真正的问题是……一旦 Visual Studio 找到 webdriver,操作就会超时,并且出现以下异常:

An unhandled exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll Additional information: Cannot start the driver service on http://localhost:(random port number that changes every time) WebDriver.dll 中发生类型为“OpenQA.Selenium.WebDriverException”的未处理异常附加信息:无法在http://localhost:(每次更改的随机端口号)上启动驱动程序服务

I have tried restarting my computer and having the system administrator check the firewall and malware blocker logs, but neither seems to have helped (or they don't know the correct thing to look for).我尝试重新启动计算机并让系统管理员检查防火墙和恶意软件拦截器日志,但似乎都没有帮助(或者他们不知道要查找的正确内容)。

I figure this is something super simple and I'm just missing it... Any help would be greatly appreciated.我认为这是非常简单的事情,我只是想念它......任何帮助将不胜感激。

Here is a copy of my code:这是我的代码的副本:

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);
        }
    }
}

Here is a copy of the debug output I receive:这是我收到的调试输出的副本:

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

I have had the same problem on my work machine, but not on my personal machine. 我在我的工作机器上遇到了同样的问题,但在我的个人机器上却没有。 The only difference I could attribute between the two was that I was using VS 2015 at home and VS 2017 at work. 我可以在两者之间唯一的区别是我在家里使用VS 2015而在工作中使用VS 2017。

What fixed it was I used the NuGet Package Manager for the project and downloaded the Selenium.Firefox.WebDriver by jbaranda, which uses the new marionette based web driver rather than gecko driver. 修复它的是我使用NuGet包管理器进行项目并下载了jbaranda的Selenium.Firefox.WebDriver,后者使用基于marionette的新驱动程序而不是gecko驱动程序。

With this installed I was able to get a firefox browser up and running without any extra configuration or options: 安装完成后,我可以启动并运行firefox浏览器,无需任何额外的配置或选项:

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

Whereas before it would throw the 'Cannot start the driver service...' exception you mentioned. 而在此之前,它会引发“无法启动驱动程序服务...”的例外情况。 There are NuGet packages for other browsers which I suggest for the particular one you're using, but the only one I didn't have that issue with was IE. 其他浏览器有NuGet包,我建议您使用的是特定的一个,但唯一一个我没有问题的是IE。 Hope that helps 希望有所帮助

I had the same issue, and had had no idea how to fix it. 我遇到了同样的问题,并且根本不知道如何修复它。 In the end I found out that the Firewall blocked the traffic to loopback. 最后我发现防火墙阻止了流量回送。 The firewall installed on the machine is McAffe. 安装在机器上的防火墙是McAffe。

All I did was stopping the service which manages traffic scan. 我所做的就是停止管理流量扫描的服务。

Hope it will help you. 希望它会对你有所帮助。

I've been hitting this consistently on IEDriverServer and rarely on FireFox. 我在IEDriverServer上一直都是这样,很少在FireFox上。

Fixed it twice when it happened on FireFox - first time I updated the gecko driver, second time I restarted my PC. 当它在FireFox上发生时修复了两次 - 第一次更新壁虎驱动程序,第二次重新启动我的PC。 Something in the environment's going on, maybe the driver does not fully quit sometimes, so new instantiations are being blocked? 环境中的某些东西正在发生,也许驱动程序有时并没有完全退出,所以新的实例化被阻止了?

I think mostly beginners face this problem when they are running Selenium with C# for the first time. 我认为大多数初学者在第一次使用C#运行Selenium时会面临这个问题。

As i also faced this situation. 因为我也面临这种情况。 As highlighted in one of the answer and let me show with images 在其中一个答案中突出显示并让我用图像显示

You have installed Selenium.webDriver but you have not installed Selenium.Firefox.WebDriver 您已安装Selenium.webDriver但尚未安装Selenium.Firefox.WebDriver

Step 1 :- Go to Nugget Manager 第1步: -转到Nugget Manager

在此输入图像描述

Step 2 :- Select Selenium.Firefox.WebDriver and install it 第2步: -选择Selenium.Firefox.WebDriver并安装它

在此输入图像描述

Now run the program once again and that problem will go away. 现在再次运行该程序,该问题将消失。

嗨,解决了吗,你能把解决方案的链接发给我吗

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在私有模式下运行Internet Explorer Selenium Web驱动程序C# - Running Internet Explorer selenium web driver in private mode c# 硒和Internet Explorer驱动程序 - Selenium and Internet Explorer Driver 无法使用C#在Selenium上使用已保存的配置文件启动Chrome驱动程序 - Can't start Chrome Driver with saved profile on Selenium with C# OpenQA.Selenium.WebDriverException Message=无法在 http://localhost:port/ 上通过 C# 中的 Selenium 使用 ChromeDriver Chrome 启动驱动程序服务 - OpenQA.Selenium.WebDriverException Message=Cannot start the driver service on http://localhost:port/ using ChromeDriver Chrome through Selenium in C# 如何使用C#中的AutoIT库在具有硒驱动程序的Internet Explorer中下载文件? - How to Download file in Internet Explorer with selenium driver using AutoIT library in C#? Selenium c#:如何在特定版本中启动Internet Explorer驱动程序(例如IE8) - Selenium c#: How to launch Internet Explorer driver in a specific version (IE8 for example) C#Selenium Internet Explorer超时 - c# selenium internet explorer timeout Selenium C#InPrivate模式Internet Explorer - Selenium C# InPrivate Mode Internet Explorer 使用.NET C#的Selenium Firefox木偶驱动程序 - Selenium Firefox Marionette Driver with .NET C# 用于 Visual Studios c# 的 PHPMyAdmin - PHPMyAdmin for visual studios c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM