c# - 为什么 Selenium 会超时?

标签 c# selenium selenium-webdriver selenium-firefoxdriver geckodriver

我正在尝试在 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 的实例化超时。下面是堆栈跟踪(删除了一些不相关的细节):

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),则一切正常。

最佳答案

正如 @FlorentB. 所指出的,我使用的是不受支持的 Firefox 版本。我转而使用 Firefox v56.0(32 位)和 geckodriver v0.19.1(32 位),一切都很好。经验教训:注意发行说明中提到的版本。

关于c# - 为什么 Selenium 会超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47202921/

相关文章:

c# - 更改 ListView 中选定行的颜色

python - python selenium 如何检查表单是否填写

python - 为什么我的 Selenium 不停止加载?

python - 在 Python 中处理数据的首选方式是什么?

PHPUnit_Selenium : Don't throw exceptions if element not found?

c# - 调用 FtpClient 一次以递归列出目录

c# - Ajax.net - 改善页面加载时间

c# - Windows Server 2008 R2 中的 ODBC 连接

java - 如何截取在 selenium 中失败的 webelement(部分屏幕而不是整个页面)

java - Selenium 网络驱动程序 : Entering text into text field -element not visible