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

查看:125
本文介绍了Selenium-Visual Studios- C#-所有(chrome,firefox和Internet Explorer)Webdrivers无法启动驱动程序服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置Selenium进行测试,但我的Web驱动程序似乎都不起作用.我尝试过在项目文件夹中移动它们,而使Visual Studios定位它们的唯一方法是使用@"path"语句.

I'm trying to set up Selenium for testing and none of my webdrivers seem to work. 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 Studio找到了webdriver,该操作就会超时,并且出现以下异常:

The real problem is... Once Visual Studio locates the webdriver, the operation times out and I get the following exception:

WebDriver.dll中发生了类型为'OpenQA.Selenium.WebDriverException'的未处理异常 附加信息:无法在 http://localhost:(random 每次更改的端口号)上启动驱动程序服务

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)

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

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.

这是我的代码的副本:

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

推荐答案

我在工作计算机上遇到了相同的问题,但在个人计算机上没有遇到同样的问题.两者之间唯一的区别是我在家中使用VS 2015,在工作中使用VS 2017.

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.

修复后的问题是,我使用了NuGet程序包管理器来下载该项目,并下载了jbaranda的Selenium.Firefox.WebDriver,它使用了新的基于 marionette 的Web驱动程序,而不是 gecko 驱动程序.

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.

安装此程序后,我可以启动并运行Firefox浏览器,而无需任何其他配置或选项:

With this installed I was able to get a firefox browser up and running without any extra configuration or options:

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

在此之前,它会引发您提到的无法启动驱动程序服务..."异常.对于其他浏览器,我建议使用NuGet软件包,但对于我所使用的特定浏览器,我建议的唯一软件包就是IE.希望有帮助

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. Hope that helps

这篇关于Selenium-Visual Studios- C#-所有(chrome,firefox和Internet Explorer)Webdrivers无法启动驱动程序服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆