C# 找不到使用c的表#

C# 找不到使用c的表#,c#,asp.net,C#,Asp.net,我试图更改表中某个特定单元格的值,但出现了一个错误,有人能看到问题所在吗?请: TestWebTable.IWebTableTests.testIWebTableTests失败:System.NullReferenceException:对象引用未设置为对象的实例。 WebTableTests.cs(37,0):位于WebTable.IWebTableTests.testIWebTableTests() 品名 模型 量 单价 全部的 以及: IWebElement table=driver.

我试图更改表中某个特定单元格的值,但出现了一个错误,有人能看到问题所在吗?请:

Test
WebTable.IWebTableTests.testIWebTableTests
失败:
System.NullReferenceException:对象引用未设置为对象的实例。
WebTableTests.cs(37,0):位于WebTable.IWebTableTests.testIWebTableTests()


品名
模型
量
单价
全部的
以及:

IWebElement table=driver.FindElement(By.CssSelector(“.cart info>table”);
ReadOnlyCollection allRows=table.FindElements(按.TagName(“tr”));
ReadOnlyCollection allCols=table.FindElements(按.TagName(“td”));
//确认它有三行
aresequal(3,allRows.Count);
//验证它是否有六列
Assert.AreEqual(5,allCols.Count);
//验证第三行的第二个单元格中是否存在指定值
Assert.AreEqual(“iPhone”,所有行[3]。FindElements(按.TagName(“td”))[1]。文本);
//进入单元格编辑器并输入一些值
字符串cellValue=allRows[3]。FindElements(按.TagName(“td”))[3]。文本;
IWebElement cellEdit=allRows[3].FindElements(按.TagName(“td”))[3];
cellEdit.Clear();
cellEdit.SendKeys(“2”);
字符串aftercellValue=allRows[3]。FindElements(按.TagName(“td”))[3]。文本;

您不认为应该命名您正在使用的工具吗?我们必须猜测什么是
IWebElement
还是方法
By
?顺便说一句,您还有一个不匹配的标记……此外,堆栈跟踪列出了行号,代码中的哪一行是第37行?NullReferenceException不难调试。使用调试器可以快速缩小问题范围。
<div class="cart-info">
   <table border="1">
     <thead>
         <tr>
            <td class="name">Product Name</td>
            <td class="model">Model</td>
            <td class="quantity">Quantity</td>
            <td class="price">Unit Price</td>
            <td class="total">Total</td>
         </tr>
     </thead>
    <tbody>
   </table>
</div>
IWebElement table = driver.FindElement(By.CssSelector(".cart-info>table"));
ReadOnlyCollection<IWebElement> allRows = table.FindElements(By.TagName("tr"));
ReadOnlyCollection<IWebElement> allCols = table.FindElements(By.TagName("td"));

//Verify that it has three rows
Assert.AreEqual(3, allRows.Count);
//Verify that it has six columns
Assert.AreEqual(5, allCols.Count);
//Verify that specified value exists in second cell of third row


Assert.AreEqual("iPhone", allRows[3].FindElements(By.TagName("td"))[1].Text);
//Get in cell editor and enter some value 

string cellValue = allRows[3].FindElements(By.TagName("td"))[3].Text;
IWebElement cellEdit = allRows[3].FindElements(By.TagName("td"))[3];
cellEdit.Clear();
cellEdit.SendKeys("2");
string aftercellValue = allRows[3].FindElements(By.TagName("td"))[3].Text;