C# 未找到FindElements会导致WebDriverException

C# 未找到FindElements会导致WebDriverException,c#,firefox,selenium,selenium-webdriver,C#,Firefox,Selenium,Selenium Webdriver,尝试在页面上运行以下FindElements方法时: var match = Driver.Instance.FindElements(By.LinkText("Click here")); 我收到错误信息: An exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll but was not handled in user code. OpenQA.Selenium.WebDriverE

尝试在页面上运行以下FindElements方法时:

var match = Driver.Instance.FindElements(By.LinkText("Click here"));
我收到错误信息:

An exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll but was not handled in user code.
OpenQA.Selenium.WebDriverException was unhandled by user code
HResult=-2146233088
Message=The HTTP request to the remote WebDriver server for URL http://localhost:7057/hub/session/a90c4828-3fb3-46d1-923d-8c5cbb65c4fe/elements timed out after 60 seconds.
Source=WebDriver
链接文本“Click here”实际上不存在于页面中,因此我不希望FindElements(By)实际找到任何内容(稍后我将在If语句中使用它)。该方法正在超时,导致上述异常

但根据我的理解,如果FindElements超时,并且实际上没有找到任何内容,它应该返回0个元素。不仅仅是超时和抛出异常

有没有其他人遇到过这个问题,或者知道是什么原因造成的?

FindElements()会抛出一个WebDriveRexeption,因为我是如何创建驱动程序的

我在自己的类中创建了驱动程序:

public class Driver
{
    public static IWebDriver Instance { get; private set; }

    public static void Initialise()
    {
        Instance = new FirefoxDriver();
        Instance.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
    }
}
这意味着在测试用例开始时,我会调用Driver.Initialise(),然后像这样使用驱动程序:

Driver.Instance.FindElements(By.Id("ABC"));
出于某种原因(我仍然不知道真正的答案),驱动程序类不是静态的,调用FindElements方法将返回WebDriverException,而不是0个元素的列表

只需将类更改为:

public static class Driver
{
    public static IWebDriver Instance { get; private set; }

    public static void Initialise()
    {
        Instance = new FirefoxDriver();
        Instance.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
    }
}

修复了问题。

xander,据我所知,findElements返回满足条件的元素集合。它可以是零个或多个元素。我希望问题是将集合分配给“var匹配”。你能不能用一个类似List eles=your findements的语句,告诉我Selenium的哪个版本,哪个浏览器,哪个版本?