Selenium C#FirefoxDriver不适用于最新的Selenium和Firefox

问题描述 投票:0回答:2

Selenium应该可以在没有开箱即用的驱动程序的情况下使用Firefox,但是我发现最新的Selenium和Firefox不是这种情况(几天前安装,Selenium 3和Firefox ERS ​​52.5)。

我跟随“Selenium C# and NUnit Pain Free Start Guide”作为一个新手,但发现简单的Selenium C#NUnit测试不适用于Firefox。

这是我的C#代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;

namespace NewSeleniumProject
{
    [TestFixture]
    public class MyFirstTest
    {
        IWebDriver driver;

        [SetUp]
        public void SetupTest()
        {
            // driver = new ChromeDriver();
            driver = new FirefoxDriver();

            //driver = new FirefoxDriver(new FirefoxBinary(@"C:\Program Files (x86)\Mozilla Firefox\Firefox.exe"), new FirefoxProfile(), TimeSpan.FromMinutes(10));

            //var options = new FirefoxOptions();
            //options.BrowserExecutableLocation = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
            //driver = new FirefoxDriver(options);

        }

        [Test]
        public void myFirstTest()
        {
            driver.Navigate().GoToUrl("http://www.swtestacademy.com");

            Assert.AreEqual("SW Test Academy - Software Test Academy", driver.Title);

            driver.Close();

            driver.Quit();
        }
    }
}

以下是我开始工作的旅程。

  • 首先,driver = new ChromeDriver()毫无障碍地为我工作。
  • 当我使用带有driver = new FirefoxDriver();的32b Firefox ERS ​​52时,我得到了“Unable to determine the current version of FireFox using the registry”错误,但Unable to determine the current version of FireFox after updated to 28.0的答案都没有解决我的问题。所以我尝试了“尝试卸载Firefox,然后重新安装它。这就是我要做的”一个。
  • Wit 64b Firefox ESR 52(和qazxsw poi),我得到了“qazxsw poi”错误。
  • 当使用driver = new FirefoxDriver();时,对于32b和64b Firefox,我得到“OpenQA.Selenium.WebDriverException : Cannot find Firefox binary in PATH or default install locations. Make sure Firefox is installed.

同样,我所关注的整个设置来自“var options = new FirefoxOptions()”。还有什么我想念的?谢谢。

更新:

这个问题与错误无关:

OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:6985/session timed out after 60 seconds.

我通过从Selenium C# and NUnit Pain Free Start Guide下载驱动程序修复了这个问题。

c# google-chrome selenium firefox
2个回答
1
投票

确保版本首先匹配。然后尝试这种方式为Firefox浏览器做。我之前遇到过相同的挑战,但这种调用Firefox的方式解决了这个问题。希望它可能有所帮助

OpenQA.Selenium.DriverServiceNotFoundException : The geckodriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. 

0
投票

所以是的,您需要将驱动程序放在应用程序的bin文件夹中,并使用带有{}的options()将.exe的路径位置传递给驱动程序服务。

我有同样的事情,但两者之间存在差异。 Firefox安装在64位文件夹中,chrome位于32位文件夹(x86)Program Files中,我相信这是问题所在,Selenium只查看应用程序.exe的32位文件夹。

当我开始使用除边缘之外的任何其他驱动程序时,我遇到了同样的问题。您可能遇到的新gecko驱动程序的另一个问题是firefox不会在请求的URL上打开。请注意,这是在VB中。虽然应该是一样的。我可能只是进行测试。

© www.soinside.com 2019 - 2024. All rights reserved.