使用火狐驱动程序的Selenium-尝试连接到随机端口号," Cannot start the driver service on http://localhost:******/"



我已经尝试在firefox中运行selenium-webdriver有一段时间了,但总是收到同样的错误:无法在上启动驱动程序服务http://localhost:******/"(数字在不断变化(我有在Chrome上使用硒元素的经验,但从未在Firefox上使用过。我遵循了一个教程,它总是适用于我的chrome网络驱动程序,可以在这里找到:https://medium.com/@tanveer.khan/dotnet-core-selenium-nunit-visual-studio-code-2d489ccb2089我已经安装了geccodriver.exe,并将其放置在多个位置(尝试了一堆在线提出的解决方案(,例如firefox浏览器位置、项目位置等。从这里:https://github.com/mozilla/geckodriver/releases我已经安装了所有需要的软件包:dotnet添加软件包。。。我从来没有选择司机的导航位置,它似乎是自动导航的。我所需要的就是什么都不做,顺利通过考试。

源代码:

using System;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System.IO;
using System.Net;
using System.Web;
using System.Globalization;
using System.Drawing.Imaging;
using OpenQA.Selenium.Firefox;
namespace DemoFox
{
class Program
{


IWebDriver driver;

[SetUp]
public void TestSetup()
{  
System.Environment.SetEnvironmentVariable("geckodriver.exe",@"C:Program FilesMozilla Firefox");     
driver= new FirefoxDriver();
driver.Navigate().GoToUrl("http://localhost:3001");
}
[Test]
public void FirefoxTest(){
Console.WriteLine("Hello firefox");
}
[TearDown]
public void TestTearDown(){
driver.Quit();
}
}
}

异常消息:

结果:失败错误消息:OpenQA.Selenium.WebDriverException:无法启动上的驱动程序服务http://localhost:58696/TearDown:System.NullReferenceException:对象引用未设置为对象的实例。堆栈跟踪:在OpenQualitySelenium.DriverService.Start((在OpenQA.Senium.Remote.DriverServiceCommandExecutior.Execute(命令命令执行(位于OpenQA.Senium.WebDriver.Execute(字符串驱动程序CommandToExecute,Dictionary`2参数(位于OpenQA.Senium.WebDriver.StartSession(ICapabilities desiredCabilities(在OpenQA.Senium.WebDriver.ctor(ICommandExecutor executor,ICapabilities功能(在OpenQA.Senium.Firefox.FirefoxDriver.ctor(FirefoxDriverService服务,FirefoxOptions选项,TimeSpan命令超时(位于OpenQA.Senium.Firefox.FirefoxDriver.ctor(FirefoxOptions选项(在OpenQualitySelenium.FirefoxDriver.ctor((位于c:\Users\Lab\Desktop\FireFoxDemo\DemoFox\Program.cs:line 24中的DemoFox.Program.TestSetup((--TearDown位于c:\Users\Lab\Desktop\FireFoxDemo\DemoFox\Program.cs:line 33中的DemoFox.Program.TestTearDown((标准输出消息:由于目标计算机主动拒绝,无法建立连接。[::ffff:120.0.1]:58696(localhost:58696(

测试总数:1。已通过:0。失败:1。跳过:0

使用驱动程序路径解决:

[SetUp]
public void TestSetup()
{  
var driverpath = @"C:Program Files (x86)Microsoft Web Driver"; //find the      driver = new FirefoxDriver(driverpath);

driver.Navigate().GoToUrl("http://localhost:3001");

driver.Manage().Window.FullScreen();

}

相关内容

最新更新