1

Excel 文件中提到的21.650值与页面上显示的值相同。但是当脚本执行时,它会读取 Excel 值,21.65并且我的断言条件变为 false。

List<string> rowValue = new List<string> { };
var ExcelFilePath = "D:\\testexcel.xlsx";

Excel.Application xlApp = new Excel.Application(ExcelFilePath);
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(ExcelFilePath);
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;

int rowCount = xlRange.Rows.Count;

for (int i = 1; i <= rowCount; i++)
{
    rowValue.Add(xlRange.Cells[i, j].Value2.ToString());

    IWebElement element = driver.FindElement(By.Id(weight_field));
    ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", element);

    string weight = driver.FindElement(By.Id(weight_field)).Text;

    if (mpuid == i)
    {  
        Assert.AreEqual(weight,rowValue[0]);
        Console.WriteLine(" Expected Value: " + rowValue[0] + " is equal to Actual Value: " + weight);
        break;
    }

    rowValue.Clear();
}
4

2 回答 2

0

在 Excel 文件中,将单元格类别更改为文本。

于 2015-09-23T06:25:07.487 回答
0

按照This SO question的答案中的建议使用 DataFormatter 类。因为这将从显示的 excel 文件中返回准确的文本。

于 2015-09-23T06:31:20.000 回答