C# 选择元素问题-webdriver-c

C# 选择元素问题-webdriver-c,c#,selenium,webdriver,nunit,selenium-webdriver,C#,Selenium,Webdriver,Nunit,Selenium Webdriver,在NUnit中运行时出现以下错误 我正在查找一个元素并将其存储在一个变量中,在尝试选择该元素时,我得到了错误。试着用这种方法 IWebElement fromitem=WebDriver.FindElementBy.Idfrom;但同样的错误依然存在。 有什么方法可以选择元素吗 注意:我用firebug验证了元素id,似乎没有问题 下面的代码 using System; using System.Collections.Generic; using System.Linq; using Syst

在NUnit中运行时出现以下错误

我正在查找一个元素并将其存储在一个变量中,在尝试选择该元素时,我得到了错误。试着用这种方法

IWebElement fromitem=WebDriver.FindElementBy.Idfrom;但同样的错误依然存在。 有什么方法可以选择元素吗

注意:我用firebug验证了元素id,似乎没有问题

下面的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.Events;
using OpenQA.Selenium.Support.PageObjects;

namespace SeleniumTests
{
[TestFixture]  
public class Sel
{
    public static IWebDriver WebDriver;
    private String baseURL;

    [SetUp] 
    public void SetupTest()
    {
        WebDriver = new FirefoxDriver(); 
        baseURL = "http://www.x-rates.com/calculator.html";
    }

    [TearDown] 
    public void TeardownTest()
    {
        WebDriver.Quit(); 
    }

    [Test]
    public void newtest()
    {
        WebDriver.Navigate().GoToUrl(baseURL + "/");

        var fromitem = WebDriver.FindElement(By.Id("from"));
        var toitem = WebDriver.FindElement(By.Id("to"));

        var fromval = new SelectElement(fromitem); //Error occurs

        var toval = new SelectElement(toitem);
        fromval.SelectByText("USD - US Dollar");
        toval.SelectByText("INR - Indian Rupee");
        WebDriver.FindElement(By.LinkText("Currency Calculator")).Click();
        var curval =   WebDriver.FindElement(By.CssSelector("span.ccOutputRslt")).GetAttribute("Value");
        var expectedValue = 61.456825;


        Thread.Sleep(900);

        Assert.AreEqual(expectedValue, curval.Trim());

    }

  }
}
SelectElement类只能用于实际的HTML元素。在您提供的页面中,所讨论的元素是一个元素,通过CSS和JavaScript添加了功能,使其能够像下拉列表一样工作。因此,尝试将其与SelectElement类一起使用将引发一个异常,指示该元素的类型不正确


“文件不存在”错误消息是一条令人费解的消息。它之所以存在,是因为NUnit试图向您展示引发异常的源代码行,这是WebDriver源代码的一部分。该行代码引发的异常应该显示在NUnit中的某个位置,该位置应该包含相应的信息消息。

我觉得您的引用好像搞乱了。您是否在应用程序中引用支持库?是否将“复制本地”设置为true?在启动测试的文件夹中,在bin文件夹中,两个WebDriver DLL都在吗?bin文件夹中有两个WebDriver DLL。支持库已被引用。将nunit框架引用的本地集复制为true。现在,我为webdriver引用设置了Copy Local为true,但仍然不起作用。@Arran-是否要我为所有引用(包括系统引用)设置Copy Local为true?