为什么Selenium超时?

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

我试图在Visual Studio 2017中将Selenium.WebDriver v3.7(来自NuGet),Firefox ESR v52.4.1(64位)和geckodriver v0.19.1连接在一起。下面是我非常简单的测试控制台应用程序。

public class Program
{
    public static void Main(string[] args)
    {
        FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"C:\geckodriver\0.19.1");
        service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe";
        IWebDriver driver = new FirefoxDriver(service);
        driver.Navigate().GoToUrl("http://news.bbc.co.uk");
    }
}

geckodriver目录也添加到我的Windows 10 PATH系统环境变量中。

然而,FirefoxDriver的实例化超时。下面是stacktrace(有几个不相关的细节被审查):

1510233068873   geckodriver     INFO    geckodriver 0.19.1
1510233068878   geckodriver     INFO    Listening on 127.0.0.1:65327
1510233070006   mozrunner::runner       INFO    Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\x\\AppData\\Local\\Temp\\rust_mozprofile.qt9HYniTrrCC"

Unhandled Exception: OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:65327/session timed out after 60 seconds. ---> System.Net.WebException: The request was aborted: The operation has timed out.
   at System.Net.HttpWebRequest.GetResponse()
   at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
   --- End of inner exception stack trace ---
   at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
   at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
   at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxDriverService service)
   at Selenium3Stuff.Program.Main(String[] args) in c:\users\x\source\repos\Selenium3Stuff\Selenium3Stuff\Program.cs:line 12

任何人都可以帮我理解发生了什么吗?如果我创建FirefoxDriver并将UseLegacyImplementation选项设置为true(因此,绕过geckodriver),那么一切正常。

c# selenium selenium-webdriver selenium-firefoxdriver geckodriver
3个回答
2
投票

正如@FlorentB所指出的,我使用的是不受支持的Firefox版本。我开始使用带有geckodriver v0.19.1(32位)的Firefox v56.0(32位),一切都很顺利。获得的经验:注意发行说明中提到的版本。


0
投票

错误说明了一切:

Unhandled Exception: OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:65327/session timed out after 60 seconds. ---> System.Net.WebException: The request was aborted: The operation has timed out.

此外,当你使用UseLegacyImplementation选项设置为true(因此,绕过geckodriver)然后一切正常。

在第一种情况下,geckodriver试图收听以某种方式占据的65327港口。因此无法完成HTTP请求并且发生System.Net.WebException

解决方案是停止任何其他服务并保持端口免费让GeckoDriver收听。如果问题仍然存在,请采取System Reboot


0
投票

我安装了Mozilla Firefox Browser v56.0(32位)和以下Nuget包:

能够使用驱动程序通过Mozilla Firefox自动打开www.google.co.in。

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